-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathgulpfile.js
51 lines (48 loc) · 1.22 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
const gulp = require('gulp')
const eslint = require('gulp-eslint')
const clear = require('clear')
const {rollup} = require('rollup')
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const moduleName = 'LazyLoadImg'
const destName = 'lazy-load-img'
// 检测代码风格
gulp.task('lint', () => {
clear()
return gulp.src(['**/*.js', '!node_modules/**', '!dist/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
// 编译开发版本
gulp.task('build:dev', ['lint'], () => {
return rollup({
entry: 'src/index.js',
plugins: [babel()]
})
.then((bundle) => {
bundle.write({
moduleName,
format: 'umd',
dest: `dist/${destName}.js`,
sourceMap: true
})
})
})
// 编译生产版本
gulp.task('build:prod', ['lint'], () => {
return rollup({
entry: 'src/index.js',
plugins: [babel(), uglify()]
})
.then((bundle) => {
bundle.write({
moduleName,
format: 'umd',
dest: `dist/${destName}.min.js`,
sourceMap: true
})
})
})
gulp.task('default', ['lint', 'build:dev', 'build:prod'])
gulp.watch(['**/**.js', '!node_modules/**', '!dist/**'], ['default'])