-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
62 lines (54 loc) · 1.27 KB
/
gulpfile.js
File metadata and controls
62 lines (54 loc) · 1.27 KB
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
const gulp = require("gulp");
const babel = require("gulp-babel");
const watch = require("gulp-watch");
const rollup = require("gulp-rollup");
const replace = require("@rollup/plugin-replace");
const entryPath = "./src/server/**/*.js";
// 清洗垃圾代码
function clearConfig() {
return gulp
.src(entryPath)
.pipe(
rollup({
input: "./src/server/config/index.js",
output: {
format: "cjs"
},
plugins: [
replace({
'process.env.NODE_ENV': "'production'"
})
]
})
)
.pipe(gulp.dest("./dist/server"));
}
function buildDev() {
return watch(entryPath, { ignoreInitial: false })
.pipe(
babel({
babelrc: false,
plugins: ["@babel/plugin-transform-modules-commonjs"]
})
)
.pipe(gulp.dest("dist/server"));
}
function buildProd() {
return gulp
.src(entryPath)
.pipe(
babel({
babelrc: false,
plugins: ["@babel/plugin-transform-modules-commonjs"]
})
)
.pipe(gulp.dest("dist/server"));
}
let build = null;
if (process.env.NODE_ENV === "development") {
build = gulp.series(buildDev);
}
if (process.env.NODE_ENV === "production") {
build = gulp.series(buildProd, clearConfig);
}
gulp.task("default", build);