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