-
Notifications
You must be signed in to change notification settings - Fork 130
/
gulpfile.esm.js
157 lines (137 loc) · 3.64 KB
/
gulpfile.esm.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import gulp from 'gulp'
import plumber from 'gulp-plumber'
import gulpIf from 'gulp-if'
import htmlhint from 'gulp-htmlhint'
import postcss from 'gulp-postcss'
import dartSass from 'sass'
import gulpSass from 'gulp-sass'
import autoprefixer from 'autoprefixer'
import cleanCSS from 'gulp-clean-css'
import rollupEach from 'gulp-rollup-each'
import rollupCommon from '@rollup/plugin-commonjs'
import rollupResolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import uglify from 'gulp-uglify'
import imagemin from 'gulp-imagemin'
import mozjpeg from 'imagemin-mozjpeg'
import pngquant from 'imagemin-pngquant'
import del from 'del'
import zip from 'gulp-zip'
const sass = gulpSass(dartSass)
const paths = {
htmls: {
src: 'src/**/*.html',
dest: 'dist/'
},
styles: {
src: 'src/css/**/*.scss',
dest: 'dist/css/'
},
scripts: {
src: 'src/js/**/*.js',
dest: 'dist/js/'
},
images: {
src: 'src/images/**/*',
dest: 'dist/images/'
},
copys: {
src: ['_locales/**/*', 'yaaw/**/*', 'background.js', 'manifest.json'],
dest: 'dist/'
},
compress: {
src: 'dist/**/*',
dest: 'dist/'
}
}
const config = {
plumberConfig: {
errorHandler: function (err) {
console.log(err.toString())
this.emit('end')
}
},
htmlhintConfig: {
'alt-require': true,
'attr-lowercase': ['viewBox', 'textLength'],
'title-require': false
},
env: {
dev: process.env.NODE_ENV === 'development',
prod: process.env.NODE_ENV === 'production'
}
}
export const clean = () => del(['dist'])
export function htmls () {
return gulp.src(paths.htmls.src)
.pipe(plumber(config.plumberConfig))
.pipe(htmlhint(config.htmlhintConfig))
.pipe(htmlhint.reporter())
.pipe(gulp.dest(paths.htmls.dest))
}
export function styles () {
return gulp.src(paths.styles.src, { sourcemaps: config.env.dev })
.pipe(plumber(config.plumberConfig))
.pipe(sass({
precision: 3,
includePaths: ['.']
}))
.pipe(postcss([
autoprefixer()
]))
.pipe(gulpIf(config.env.prod, cleanCSS()))
.pipe(gulp.dest(paths.styles.dest), { sourcemaps: config.env.dev })
}
export function scripts () {
return gulp.src(paths.scripts.src, { sourcemaps: config.env.dev })
.pipe(plumber(config.plumberConfig))
.pipe(rollupEach({
isCache: true,
plugins: [
rollupCommon(),
rollupResolve({
browser: true
}),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VUE_ENV': JSON.stringify('browser')
})
]
},
{
format: 'iife'
}
))
.pipe(gulpIf(config.env.prod, uglify()))
.pipe(gulp.dest(paths.scripts.dest), { sourcemaps: config.env.dev })
}
export function images () {
return gulp.src(paths.images.src)
.pipe(plumber(config.plumberConfig))
.pipe(imagemin([
pngquant(),
mozjpeg()
], {
verbose: true
}))
.pipe(gulp.dest(paths.images.dest))
}
export function copys () {
return gulp.src(paths.copys.src, { base: '.' })
.pipe(gulp.dest(paths.copys.dest))
}
export function watch () {
gulp.watch(paths.htmls.src, htmls)
gulp.watch(paths.scripts.src, scripts)
gulp.watch(paths.styles.src, styles)
gulp.watch(paths.copys.src, copys)
}
export function compress () {
return gulp.src(paths.compress.src)
.pipe(zip('chrome.zip'))
.pipe(gulp.dest(paths.compress.dest))
}
export const build = gulp.parallel(htmls, styles, scripts, images, copys)
export const serve = gulp.series(clean, build, watch)
export const publish = gulp.series(clean, build, compress)