-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
109 lines (100 loc) · 2.65 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
103
104
105
106
107
108
109
var config = require("./build/config.js"),
gulp = require("gulp"),
gulpSequence = require("gulp-sequence"),
gutil = require("gulp-util"),
del = require("del"),
uglify = require("gulp-uglify"),
imagemin = require("gulp-imagemin"),
express = require("express"),
webpack = require("webpack"),
webpackDevMiddleware = require("webpack-dev-middleware"),
webpackHotMiddleware = require("webpack-hot-middleware"),
history = require("connect-history-api-fallback"),
proxyMiddleware = require("http-proxy-middleware"),
opn = require("opn");
// 开发服务器
gulp.task("dev", function() {
var webpackDevConfig = require("./build/webpack.dev.js");
webpackDevConfig.entry = ["webpack-hot-middleware/client?quiet=true"].concat([
webpackDevConfig.entry
]);
var devCompiler = webpack(webpackDevConfig);
var devMiddleware = webpackDevMiddleware(devCompiler, {
publicPath: webpackDevConfig.output.publicPath,
stats: {
chunks: false,
colors: true,
timings: true,
source: true,
cachedAssets: false
},
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 300,
poll: true
}
});
var hotMiddleware = webpackHotMiddleware(devCompiler, {
log: false
});
var server = express();
server.use(history());
if (config.target)
server.use(
proxyMiddleware("/api", {
target: config.target,
changeOrigoin: true,
pathRewrite: { "^/api": "/" }
})
);
server.use(devMiddleware);
server.use(hotMiddleware);
server.listen(3008, function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
opn("http://localhost:3008");
});
});
//清除
gulp.task("clean", function(cb) {
del.sync("dist");
cb();
});
//图片压缩
gulp.task("copyImg", function() {
return gulp
.src("img/**/*.*")
.pipe(imagemin())
.pipe(gulp.dest("dist/img/"));
});
//复制无需编译的js文件
gulp.task("copyJs", function() {
return gulp
.src([
"src/js_modules/react/pro/react.js",
"src/js_modules/react-dom/pro/react-dom.js"
])
.pipe(uglify())
.pipe(gulp.dest("dist/js/"));
});
//webpack production
gulp.task("webpackPro", function(cb) {
var webpackProConfig = require("./build/webpack.pro.js");
webpack(webpackProConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack:production", err);
gutil.log(
"[webpack:production]",
stats.toString({
chunks: false,
colors: true,
timings: true,
source: true,
cachedAssets: false
})
);
cb();
});
});
gulp.task(
"build",
gulpSequence("clean", "copyImg", "webpackPro")
);