forked from think2011/localResizeIMG
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
executable file
·102 lines (86 loc) · 2.39 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
91
92
93
94
95
96
97
98
99
100
101
102
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var webpackConfig = require('./webpack.config');
var packageJSON = require('./package.json');
var webpack = require("webpack");
var paths = {
src : 'src',
dist: 'dist',
test: 'test'
};
var files = {
js : paths.src + "/**/*.js",
txt : paths.src + "/**/*.txt",
html : paths.test + '/**/*.html',
lrzAll : paths.dist + '/lrz.all.bundle.js',
lrzAllMap: paths.dist + '/lrz.all.bundle.js.map'
};
// 默认
gulp.task('default', ['clean'], function () {
gulp.start('watch');
});
// 开发
gulp.task('dev', function () {
gulp.start([
'dev:js',
'build:html'
]);
});
// 发布
gulp.task('build', ['clean'], function () {
gulp.start([
'build:js',
'build:html',
'build:copy'
]);
});
// 监听
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 () {
webpackConfig.devtool = ['source-map'];
webpackConfig.plugins = [
new webpack.optimize.UglifyJsPlugin({
compress : {
warnings: false
},
output : {
comments : false,
semicolons: true
},
sourceMap: true
})
];
return gulp.src(paths.src + "/lrz.js")
.pipe(plugins.webpack(webpackConfig))
.pipe(plugins.replace(/__packageJSON\.version__/g, packageJSON.version))
.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));
});
gulp.task('build:copy', ['build:html'], function () {
// 未来可能可能采用 #48
/* gulp.src(files.lrzAll)
.pipe(plugins.rename('index.js'))
.pipe(gulp.dest('./'));
gulp.src(files.lrzAllMap)
.pipe(plugins.rename('index.js.map'))
.pipe(gulp.dest('./'));*/
return gulp.src(files.txt)
.pipe(gulp.dest(paths.dist));
});