-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (53 loc) · 1.52 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
let fs = require('fs')
let path = require('path')
let gulp = require('gulp')
let autoprefixer = require('gulp-autoprefixer')
let cssnano = require('gulp-cssnano')
let gulpif = require('gulp-if')
let plumber = require('gulp-plumber')
let stylus = require('gulp-stylus')
let sourcemaps = require('gulp-sourcemaps')
let {NODE_ENV} = process.env
let dev = NODE_ENV === 'development'
let prd = NODE_ENV === 'production'
let webpack
let bundlerConfig
let bundler
let patterns = {
static: 'src/{popup.html,manifest.json}',
js: 'src/**/*.js',
styl: 'src/**/*.styl'
}
gulp.task('static', () => gulp.src(patterns.static).pipe(gulp.dest('dist')))
gulp.task('stylus', () =>
gulp
.src('src/index.styl')
.pipe(plumber())
.pipe(gulpif(dev, sourcemaps.init()))
.pipe(stylus())
.pipe(autoprefixer())
.pipe(gulpif(prd, cssnano()))
.pipe(gulpif(dev, sourcemaps.write('.')))
.pipe(gulp.dest('dist'))
)
gulp.task('webpack-init', done => {
webpack = require('webpack')
bundlerConfig = require('./webpack.config')
bundler = webpack(bundlerConfig)
done()
})
gulp.task('webpack', done => {
bundler.run((err, res) => {
if (err !== null && err !== undefined) {
console.error('error bundling', err)
}
done()
})
})
gulp.task('watch', () => {
gulp.watch(patterns.static, ['static'])
gulp.watch(patterns.styl, ['stylus'])
gulp.watch(patterns.js, ['webpack'])
})
gulp.task('dev', ['static', 'stylus', 'webpack-init', 'webpack', 'watch'])
gulp.task('prd', ['static', 'stylus', 'webpack-init', 'webpack'])