forked from think2011/localResizeIMG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·68 lines (57 loc) · 1.48 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var webpackConfig = require('./webpack.config');
var packageJSON = require('./package.json');
var paths = {
src : './src',
dist: './dist',
test: './test'
};
var files = {
js : [paths.src + "/**/*.js"],
html: paths.test + '/**/*.html'
};
// 默认
gulp.task('default', ['clean'], function () {
gulp.start('watch');
});
// 开发
gulp.task('dev', function () {
gulp.start([
'dev:js'
]);
});
// 发布
gulp.task('build', ['clean'], function () {
gulp.start([
'build:js',
'build:html'
]);
});
// 监听
gulp.task('watch', ['dev'], function () {
gulp.watch(files.js, ['dev:js']);
});
// 清洁
gulp.task('clean', function () {
return gulp.src(paths.dist)
.pipe(plugins.clean({force: true}));
});
gulp.task('dev:js', function () {
webpackConfig.devtool = ['source-map'];
return gulp.src(files.js)
.pipe(plugins.webpack(webpackConfig))
.pipe(gulp.dest(paths.dist));
});
gulp.task('build:js', function () {
return gulp.src(files.js)
.pipe(plugins.webpack(webpackConfig))
.pipe(plugins.replace(/__packageJSON\.version__/g, packageJSON.version))
.pipe(plugins.uglify())
.pipe(gulp.dest(paths.dist));
});
gulp.task('build:html', ['build:js'], function () {
return gulp.src(files.html)
.pipe(plugins.staticHash({asset: paths.dist}))
.pipe(gulp.dest(paths.test));
});