-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
90 lines (78 loc) · 1.93 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
'use strict'
const path = require('path')
const gulp = require('gulp')
const browserSync = require('browser-sync').create()
const PATH_CSS = './src/css/'
const FILES_CSS = './src/css/*.styl'
const FILES_HTML = './src/*.html'
const VENDOR_FILES = [
'./node_modules/normalize.css/normalize.css',
'./node_modules/cmui-zero/dist/zero.css',
]
gulp.task('vendor', () => {
return gulp.src(VENDOR_FILES)
.pipe(gulp.dest(path.join(PATH_CSS, 'vendor')))
})
gulp.task('css', () => {
const stylus = require('gulp-stylus')
const postcss = require('gulp-postcss')
const autoprefixer = require('autoprefixer')
const AUTOPREFIXER_BROWSERS = [
'last 2 Safari versions',
'last 2 Chrome versions',
'last 2 Firefox versions',
'Android >= 4',
'iOS >= 7',
]
function logError(err) {
let plugin = err.plugin || ''
const nameMapping = {
'gulp-stylus': 'Stylus',
'gulp-postcss': 'PostCSS',
}
const pluginName = nameMapping[plugin] || 'Unknown'
console.error(`\n[${pluginName}] Compiling Error!\n`)
console.error(err.stack || err.message)
console.error('\n')
browserSync.notify(`<span style="color: red; font-family: sans-serif; font-weight: bold;"><code>${pluginName}</code> Compiling Error!</span>`)
this.emit('end')
}
return gulp.src(FILES_CSS)
.pipe(stylus({
linenos: true,
compress: false,
errors: true,
'include css': true,
}))
.on('error', logError)
.pipe(postcss([
autoprefixer({
browsers: AUTOPREFIXER_BROWSERS,
}),
]))
.on('error', logError)
.pipe(gulp.dest(PATH_CSS))
.pipe(browserSync.stream())
})
gulp.task('watch-css', () => {
gulp.watch(FILES_CSS, gulp.series('css'))
})
gulp.task('watch-html', () => {
gulp.watch(FILES_HTML)
.on('change', browserSync.reload)
})
gulp.task('serve', (done) => {
browserSync.init({
server: './src/',
})
done()
})
gulp.task('default', gulp.series([
'vendor',
'css',
'serve',
gulp.parallel([
'watch-css',
'watch-html',
]),
]))