-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
70 lines (59 loc) · 1.58 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
const gulp = require('gulp')
const plugins = require('gulp-load-plugins')()
const source = require('vinyl-source-stream')
const del = require('del')
const createBundler = require('./create_bundler')
const {rev, uglifycss, autoprefixer, sass} = plugins
const gutil = plugins.util
gulp.task('default', ['build'])
gulp.task('build', ['sass', 'browserify'])
gulp.task('browserify', function () {
return createBundler({uglify: true})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/js/'))
})
gulp.task('watch',['revision:clear'], function () {
gulp.watch('./src/scss/**/*.scss', ['sass'])
const b = createBundler({watch: true})
function bundle() {
b.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/js/'))
}
bundle()
b.on('update', bundle)
b.on('log', gutil.log)
})
gulp.task('sass', function () {
return gulp.src('./src/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(uglifycss({
"maxLineLen": 80
}))
.pipe(gulp.dest('./build/css'))
})
gulp.task('revision:clear', function () {
return del([
'rev-manifest.json'
])
})
gulp.task('revision', function () {
const assets = [
'build/css/styles.css',
'build/js/bundle.js'
]
return gulp.src(assets, {base: 'assets'})
.pipe(gulp.dest('build'))
.pipe(rev())
.pipe(gulp.dest('build'))
.pipe(rev.manifest({
base: 'build',
merge: true
}))
.pipe(gulp.dest('build'));
})