-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
98 lines (84 loc) · 2.02 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// BrowserSync Base Dir
var baseDir = './';
var htmlPath = './**/*.html';
// Sass and Js Path
var sassPath = [
'./src/butterCake.scss'
];
var sassWatch = './src/**/*.scss';
// Dist Path
var sassDist = './dist/css';
// Javascript
var jsPath = [
'./dist/js/butterCake.js',
];
var jsWatch = './dist/js/**/*.js';
// Dist Path
var jsDist = './dist/js';
// Requires
var gulp = require("gulp");
var sass = require("gulp-sass");
var postcss = require("gulp-postcss");
var autoprefixer = require('autoprefixer');
// var postcssSass = require("postcss-sass");
var cssnano = require("cssnano");
var uglify = require("gulp-uglify");
var pipeline = require('readable-stream').pipeline;
var rename = require("gulp-rename");
var browser = require("browser-sync").create();
var concat = require('gulp-concat');
var babel = require('gulp-babel');
// Compile scss into css
function scss() {
return gulp.src(sassPath)
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(sassDist))
.pipe(postcss([cssnano()]))
.pipe(rename({
dirname: '/min',
suffix: '.min'
}))
.pipe(gulp.dest(sassDist))
.pipe(browser.stream())
}
// Compile Latest js into es5
function js() {
return gulp.src(jsPath)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest(jsDist))
.pipe(uglify())
.pipe(rename({
dirname: '/min',
suffix: '.min'
}))
.pipe(gulp.dest(jsDist))
.pipe(browser.stream())
}
// Concat all js into one
function concatjs() {
return gulp.src(jsWatch)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(concat('/compiled-all.min.js'))
.pipe(uglify())
.pipe(gulp.dest(jsDist))
}
// Watch Changes
function watch() {
browser.init({
server: {
baseDir: baseDir
}
});
gulp.watch(sassWatch, scss);
gulp.watch(htmlPath).on('change', browser.reload);
// gulp.watch(jsWatch, js);
// gulp.watch(jsPath).on('change', browser.reload);;
}
exports.scss = scss;
exports.watch = watch;
exports.concat = concatjs;