1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | require('babel-polyfill');
|
8 | require('babel-register')({
|
9 | presets: ['es2015', 'react', 'stage-0'],
|
10 | plugins: ['transform-runtime', 'add-module-exports']
|
11 | });
|
12 |
|
13 | var init = require('./lib/common/init'),
|
14 | log = require('./lib/common/log'),
|
15 | deleteDir = require('./lib/common/deleteDir'),
|
16 | path = require('path');
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var builder = function builder(options, cb) {
|
40 | log("building file!");
|
41 | options = options || {};
|
42 | options.isProd = true;
|
43 |
|
44 |
|
45 | var opts = init(options),
|
46 | env = opts.getEnv(),
|
47 | distPath = path.resolve(env.workDir, env.outPath);
|
48 |
|
49 | log('remove dist file:', distPath);
|
50 | deleteDir(distPath, false);
|
51 |
|
52 | var webpack = require('webpack'),
|
53 | config = require('./lib/scripts/webpack.ser'),
|
54 | compiler = webpack(config);
|
55 | compiler.run(function (err, stats) {
|
56 | err ? function () {
|
57 | log('build error! info:', err);
|
58 | process.exit(0);
|
59 | }() : function () {
|
60 | log("build success");
|
61 | cb ? cb() : process.exit(0);
|
62 | }();
|
63 | });
|
64 | };
|
65 |
|
66 | module.exports = builder; |
\ | No newline at end of file |