-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
79 lines (64 loc) · 1.73 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
const { src, watch, dest, series } = require('gulp');
// Webpack Config
const webpack = require('webpack');
const webConfig = require('./config/webpack.config.js');
// Importing Gulp Plugins.
const sass = require('gulp-sass');
const uglifycss = require('gulp-uglifycss');
const rename = require("gulp-rename");
const sync = require('browser-sync').create();
/* *** Scripting *****/
// For Scss to CSS
const scssToCss = (cb) => {
// where is file
return src('./scss/*.scss')
// pass file through the sass compiler
.pipe(sass().on('error', sass.logError))
.pipe(rename('style.min.css'))
.pipe(uglifycss({
"uglyComments": true
}))
// where Do I save
.pipe(dest('./dist/'))
// stream change all browsers
.pipe(sync.stream())
cb();
}
// for CSS to Min.CSS
const uglifyCss = () => {
return src('./css/*.css')
.pipe(rename('style.min.css'))
.pipe(uglifycss({
"uglyComments": true
}))
.pipe(dest('./dist/'))
.pipe(sync.stream())
}
// For weback
const webpackAssests = (cb) => {
return new Promise((resolve, reject) => {
webpack(webConfig, (err, stats) => {
if ( err ) {
return reject(err)
}
if( stats.hasErrors() ) {
return reject(new Error(stats.compilation.errors.join('\n')))
}
resolve();
})
})
}
// Watching & server
const watchDir = (cb) => {
sync.init({
server: {
baseDir: './dist/'
}
});
watch('./scss/*.scss', scssToCss);
watch('./js/*.js', webpackAssests).on('change', sync.reload);
// watch('./js/*.js', transfiler)
watch('./dist/*.html').on('change', sync.reload);
}
exports.default = watchDir;
exports.build = webpackAssests;