forked from serverless-heaven/serverless-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
50 lines (39 loc) · 1.32 KB
/
compile.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
'use strict';
const _ = require('lodash');
const BbPromise = require('bluebird');
const webpack = require('webpack');
const tty = require('tty');
module.exports = {
compile() {
this.serverless.cli.log('Bundling with Webpack...');
const compiler = webpack(this.webpackConfig);
return BbPromise
.fromCallback(cb => compiler.run(cb))
.then(stats => {
if (!this.multiCompile) {
stats = { stats: [stats] };
}
const compileOutputPaths = [];
const consoleStats = this.webpackConfig.stats || _.get(this, 'webpackConfig[0].stats') || {
colors: tty.isatty(process.stdout.fd),
hash: false,
version: false,
chunks: false,
children: false
};
_.forEach(stats.stats, compileStats => {
const statsOutput = compileStats.toString(consoleStats);
if (statsOutput) {
this.serverless.cli.consoleLog(statsOutput);
}
if (compileStats.compilation.errors.length) {
throw new Error('Webpack compilation error, see above');
}
compileOutputPaths.push(compileStats.compilation.compiler.outputPath);
});
this.compileOutputPaths = compileOutputPaths;
this.compileStats = stats;
return BbPromise.resolve();
});
},
};