1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const winston = require('winston');
|
12 |
|
13 | const {Compiler} = require('../build/compiler.js');
|
14 |
|
15 | exports.run = async function(
|
16 | {
|
17 | dir = '.',
|
18 | production,
|
19 | preserveNames,
|
20 | maxWorkers,
|
21 | logLevel,
|
22 | minify,
|
23 | experimentalServerless,
|
24 | modernBuildOnly,
|
25 | skipSourceMaps,
|
26 | } /*: {
|
27 | experimentalServerless: boolean,
|
28 | dir: string,
|
29 | production: boolean,
|
30 | maxWorkers?: number,
|
31 | preserveNames: boolean,
|
32 | logLevel: string,
|
33 | minify: boolean,
|
34 | modernBuildOnly: boolean,
|
35 | skipSourceMaps: boolean,
|
36 | }*/
|
37 | ) {
|
38 | const logger = winston.createLogger({
|
39 | format: winston.format.combine(
|
40 | winston.format.colorize(),
|
41 | winston.format.simple()
|
42 | ),
|
43 | });
|
44 | logger.add(new winston.transports.Console({level: logLevel}));
|
45 |
|
46 | const env = production ? 'production' : 'development';
|
47 |
|
48 | const compiler = new Compiler({
|
49 | env,
|
50 | dir,
|
51 | logger,
|
52 | preserveNames,
|
53 | minify,
|
54 | serverless: experimentalServerless,
|
55 | modernBuildOnly,
|
56 | maxWorkers,
|
57 | skipSourceMaps,
|
58 | });
|
59 |
|
60 | await compiler.clean();
|
61 |
|
62 | await new Promise((resolve, reject) => {
|
63 | compiler.start((err, stats) => {
|
64 | if (err || stats.hasErrors()) {
|
65 | return reject(err || new Error('Compiler stats included errors.'));
|
66 | }
|
67 | return resolve();
|
68 | });
|
69 | });
|
70 |
|
71 | return compiler;
|
72 | };
|