-
Notifications
You must be signed in to change notification settings - Fork 56
/
gulpfile.js
executable file
·82 lines (70 loc) · 2.04 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
let gulp = require('gulp')
let gutil = require('gulp-util')
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 = {
styl: '{src,themes/learn-plasma/src}/**/*.styl',
js: '{src,themes/learn-plasma/src}/**/*.js',
fonts: ['themes/learn-plasma/src/fonts/*','node_modules/@fortawesome/fontawesome-free/webfonts/*']
}
gulp.task('fonts', () =>
gulp
.src(patterns.fonts)
.pipe(gulp.dest('themes/learn-plasma/source/webfonts'))
)
gulp.task('stylus', () =>
gulp
.src('themes/learn-plasma/src/index.styl')
.pipe(plumber())
.pipe(gulpIf(dev, sourcemaps.init()))
.pipe(
stylus({
'include css': true
})
)
.pipe(autoprefixer())
.pipe(gulpIf(prd, cssnano()))
.pipe(gulpIf(dev, sourcemaps.write('.')))
.pipe(gulp.dest('themes/learn-plasma/source'))
)
gulp.task('webpack-init', done => {
webpack = require('webpack')
bundlerConfig = require('./webpack.config')
bundler = webpack(bundlerConfig)
done()
})
gulp.task('webpack', done => {
bundler.run((err, stats) => {
if (err !== undefined && err !== null) {
console.error('error bundling', err)
}
if (stats.hasWarnings() === true) {
stats.toJson().warnings.forEach(item => {
gutil.log.warn('webpack warning', item)
})
}
if (stats.hasErrors() === true) {
stats.toJson().warnings.forEach(item => {
gutil.log.error('error', item)
})
}
done()
})
})
gulp.task('watch', () => {
gulp.watch(patterns.styl, gulp.series('stylus'))
gulp.watch(patterns.js, gulp.series('webpack'))
})
gulp.task('build', gulp.parallel('fonts', 'stylus', 'webpack-init', 'webpack'))
gulp.task('dev', gulp.parallel('build', 'watch'))
gulp.task('prd', gulp.series('build'))