-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (75 loc) · 1.72 KB
/
index.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
/**
* @tailor start
* @author Leon.Cai
*/
"use strict";
const Webpack = require("webpack"),
Path = require("path"),
FSE = require("fs-extra"),
Log = require("./lib/util/log"),
Shell = require("shelljs"),
Config = require("./config"),
Server = require("./server"),
ENV = require("./constant/env.js");
/**
* run tailor
* @param {[type]} config [description]
* @return {[type]} [description]
*/
function run(config) {
let webpackConfig = Config(config),
outputConfig = config.output,
compiler = null;
Log.info(`
work info:
path: ${Path.join(config.root)}
env: ${config.env}
parallel: ${config.parallel}
env info:
buildPath: ${outputConfig.path}
publicPath: ${outputConfig.publicPath}
`);
Log.info("Enjoy yourself! :)");
if (outputConfig.clean) {
let outputPath = Path.join(config.root, outputConfig.path);
FSE.existsSync(outputPath) &&
(Shell.rm("-rf", outputPath),
Log.info("clean " + Log.chalk.blue(outputPath) + " done"));
}
compiler = Webpack(webpackConfig);
if (config.env === ENV.dev) {
Server(config, compiler);
} else {
compiler.run(compilerCallback);
}
return compiler;
}
/**
* compiler callback
* @param {Object} err [description]
* @param {Object} stat [description]
*/
function compilerCallback(err, stat) {
if (err) {
Log.error(err.stack);
process.exit(1);
}
const Stats = stat.toJson();
if (Stats.errors.length !== 0) {
Log.error(Stats.errors);
process.exit(1);
}
// 输出构建结果
process.stdout.write(
stat.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + "\n"
);
Log.info("Build successfully!");
process.exit(0);
}
module.exports = run;