Files
serverless-webpack/lib/compile.js
T
2016-09-07 11:55:02 +08:00

34 lines
918 B
JavaScript

'use strict';
const BbPromise = require('bluebird');
const webpack = require('webpack');
module.exports = {
compile() {
this.serverless.cli.log('Bundling with Webpack...');
const compiler = webpack(this.webpackConfig);
return BbPromise
.fromCallback(cb => compiler.run(cb))
.then(stats => {
this.serverless.cli.consoleLog(stats.toString({
colors: true,
hash: false,
version: false,
chunks: false,
children: false
}));
if (stats.compilation.errors.length) {
throw new Error('Webpack compilation error, see above');
}
const outputPath = stats.compilation.compiler.outputPath;
this.webpackOutputPath = outputPath;
this.originalServicePath = this.serverless.config.servicePath;
this.serverless.config.servicePath = outputPath;
return stats;
});
},
};