snappymail/tasks/webpack.js

39 lines
1 KiB
JavaScript
Raw Normal View History

2019-06-29 22:16:09 +08:00
/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL 3 */
const webpack = require('webpack');
const gutil = require('gulp-util');
2019-07-05 03:09:27 +08:00
const { config } = require('./config');
2019-06-29 22:16:09 +08:00
const webpackCfgBuilder = require('../webpack.config.builder.js');
const webpackError = (err) => {
if (err) {
gutil.log('[webpack]', '---');
gutil.log('[webpack]', err.error ? err.error.toString() : '');
gutil.log('[webpack]', err.message || '');
gutil.log('[webpack]', '---');
}
};
const webpackCallback = (done) => (err, stats) => {
if (err) {
if (config.watch) {
webpackError(err);
} else {
throw new gutil.PluginError('webpack', err);
}
} else if (stats && stats.compilation && stats.compilation.errors && stats.compilation.errors[0]) {
if (config.watch) {
stats.compilation.errors.forEach(webpackError);
} else {
throw new gutil.PluginError('webpack', stats.compilation.errors[0]);
}
}
done();
};
exports.webpack = (done) => {
2019-07-05 03:09:27 +08:00
webpack(webpackCfgBuilder(config.paths.staticJS, !config.community, 'production'), webpackCallback(done));
2019-06-29 22:16:09 +08:00
};