-
Notifications
You must be signed in to change notification settings - Fork 276
/
gulpfile.js
91 lines (82 loc) · 2.09 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
const gulp = require('gulp'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('autoprefixer'),
webpack = require('webpack'),
sass = require('gulp-sass')(require('sass')),
browserSync = require('browser-sync').create()
/* ========== develop ========== */
// webpack
function execWebpack(cb) {
webpack(require('./webpack.dev.js'), function (err) {
if (err) return cb(err)
cb()
})
}
// sass
function execSass() {
return gulp
.src(['src/scss/style.scss', 'src/scss/mobile.scss', 'src/scss/dark.scss'])
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./source/css/'))
}
// browser-sync
// watch js
const reloadJs = gulp.series(execWebpack, function (done) {
browserSync.reload()
done()
})
// watch sass
const reloadCss = gulp.series(execSass, function (done) {
browserSync.reload()
done()
})
// watch layout
function reloadLayout(done) {
browserSync.reload()
done()
}
// watch _config
function reloadConfig(done) {
browserSync.reload()
done()
}
exports.dev = gulp.series(execWebpack, execSass, function (cb) {
browserSync.init({
proxy: 'localhost:4000',
})
gulp.watch(['./src/js/**/*.js'], reloadJs)
gulp.watch(['./src/scss/**/*.scss'], reloadCss)
gulp.watch(['./layout/**/*.ejs'], reloadLayout)
gulp.watch(['./_config.yml'], reloadConfig)
cb()
})
/* ========== bulid ========== */
// webpack-prod
function webpackProd(cb) {
webpack(require('./webpack.prod.js'), function (err) {
if (err) return cb(err)
cb()
})
}
// sass-prod
function sassProd() {
return gulp
.src(['src/scss/style.scss', 'src/scss/mobile.scss', 'src/scss/dark.scss'])
.pipe(sourcemaps.init())
.pipe(
sass({
outputStyle: 'compressed',
}).on('error', sass.logError),
)
.pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./source/css/'))
}
exports.build = gulp.series(webpackProd, sassProd, function (cb) {
cb()
console.log(process.argv)
})