-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (71 loc) · 2.11 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
const gulp = require('gulp')
const gulpLoadPlugins = require('gulp-load-plugins')
const browserSync = require('browser-sync').create()
const del = require('del')
const runSequence = require('run-sequence')
const autoprefixer = require('autoprefixer')
const cssnano = require('cssnano')
const uncss = require('postcss-uncss')
const $ = gulpLoadPlugins()
const reload = browserSync.reload
let dev = true
gulp.task('styles', () => {
return gulp.src('src/styles/*.scss')
.pipe($.plumber())
.pipe($.if(dev, $.sourcemaps.init()))
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.postcss([
autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']})
]))
.pipe($.if(dev, $.sourcemaps.write()))
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({stream: true}))
})
gulp.task('build', ['clean'], () => {
runSequence(['styles'], () => {
return gulp.src('src/index.html')
.pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
.pipe($.if(/\.css$/, $.postcss([
uncss({html: ['src/*.html']}),
])))
// .pipe($.if('*.css', $.rev()))
.pipe($.if('*.css', $.stripCssComments({preserve: false})))
// .pipe($.if('*.css', $.cleanCss({format: 'beautify'})))
// .pipe(gulp.dest('dist')) // save unminified version
.pipe($.if(/\.css$/, $.postcss([
cssnano({safe: false, autoprefixer: true})
])))
// .pipe($.if(/\.css$/, $.rename({ extname: '.min.css' })))
// .pipe($.revReplace())
.pipe(gulp.dest('dist'))
})
})
gulp.task('clean', del.bind(null, ['.tmp', 'dist']))
gulp.task('serve', () => {
runSequence(['clean'], ['styles'], () => {
browserSync.init({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'src', '.']
}
})
gulp.watch([
'src/*.html'
]).on('change', reload)
gulp.watch('src/styles/**/*.scss', ['styles'])
})
})
gulp.task('serve:dist', ['build'], () => {
browserSync.init({
notify: false,
port: 9000,
server: {
baseDir: ['dist']
}
})
})