2016-08-20 01:15:37 +03:00
|
|
|
/* eslint-disable max-len, import/no-extraneous-dependencies */
|
2016-03-08 00:21:12 +03:00
|
|
|
import path from 'path';
|
|
|
|
|
2016-04-28 00:06:27 +03:00
|
|
|
import config from 'config';
|
2016-03-08 00:21:12 +03:00
|
|
|
import ExtractTextPlugin from 'extract-text-webpack-plugin';
|
2017-05-18 00:07:06 +03:00
|
|
|
import SriPlugin from 'webpack-subresource-integrity';
|
2016-08-20 01:15:37 +03:00
|
|
|
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
|
2018-08-02 16:13:41 +03:00
|
|
|
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
|
2016-04-25 23:07:36 +03:00
|
|
|
|
2017-05-18 00:07:06 +03:00
|
|
|
import SriDataPlugin from './src/core/server/sriDataPlugin';
|
|
|
|
import { getPlugins, getRules } from './webpack-common';
|
2018-06-27 18:51:33 +03:00
|
|
|
import webpackIsomorphicToolsConfig from './src/core/server/webpack-isomorphic-tools-config';
|
2016-08-20 01:15:37 +03:00
|
|
|
|
2016-04-28 00:06:27 +03:00
|
|
|
const appName = config.get('appName');
|
|
|
|
const appsBuildList = appName ? [appName] : config.get('validAppNames');
|
2016-04-22 19:42:57 +03:00
|
|
|
|
|
|
|
const entryPoints = {};
|
|
|
|
for (const app of appsBuildList) {
|
2017-05-23 00:02:23 +03:00
|
|
|
entryPoints[app] = `${app}/client`;
|
2016-04-22 19:42:57 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 19:38:32 +03:00
|
|
|
export default {
|
2016-03-08 00:21:12 +03:00
|
|
|
devtool: 'source-map',
|
2016-04-28 00:06:27 +03:00
|
|
|
context: path.resolve(__dirname),
|
2016-04-22 19:42:57 +03:00
|
|
|
entry: entryPoints,
|
2016-03-08 00:21:12 +03:00
|
|
|
output: {
|
2017-05-18 00:07:06 +03:00
|
|
|
crossOriginLoading: 'anonymous',
|
2016-04-28 00:06:27 +03:00
|
|
|
path: path.join(__dirname, 'dist'),
|
2016-04-22 19:42:57 +03:00
|
|
|
filename: '[name]-[chunkhash].js',
|
|
|
|
chunkFilename: '[name]-[chunkhash].js',
|
2016-05-27 16:28:19 +03:00
|
|
|
publicPath: config.has('staticHost') ? `${config.get('staticHost')}/` : '/',
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
module: {
|
2017-05-18 00:07:06 +03:00
|
|
|
rules: getRules(),
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
2017-11-10 00:24:07 +03:00
|
|
|
node: {
|
|
|
|
// This allows us to use `__filename` in our code base, for instance to
|
|
|
|
// have unique names in the error handlers.
|
|
|
|
__filename: true,
|
|
|
|
},
|
2016-03-08 00:21:12 +03:00
|
|
|
plugins: [
|
2017-05-18 00:07:06 +03:00
|
|
|
...getPlugins(),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: '[name]-[contenthash].css',
|
|
|
|
allChunks: true,
|
2016-04-25 23:07:36 +03:00
|
|
|
}),
|
2016-03-08 00:21:12 +03:00
|
|
|
// optimizations
|
2018-08-02 16:13:41 +03:00
|
|
|
new UglifyJsPlugin({
|
2018-09-22 00:12:34 +03:00
|
|
|
// Even though devtool is set to source-map, this must be true to output source maps:
|
|
|
|
sourceMap: true,
|
2018-08-02 16:13:41 +03:00
|
|
|
// Do not change these options without busting the cache.
|
|
|
|
// See: https://github.com/mozilla/addons-frontend/issues/5796
|
|
|
|
uglifyOptions: {
|
|
|
|
output: {
|
|
|
|
comments: false,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
drop_console: true,
|
|
|
|
},
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig),
|
2017-05-18 00:07:06 +03:00
|
|
|
new SriPlugin({ hashFuncNames: ['sha512'] }),
|
|
|
|
new SriDataPlugin({
|
|
|
|
saveAs: path.join(__dirname, 'dist', 'sri.json'),
|
|
|
|
}),
|
2017-01-09 14:51:01 +03:00
|
|
|
// This function helps ensure we do bail if a compilation error
|
|
|
|
// is encountered since --bail doesn't cause the build to fail with
|
|
|
|
// uglify errors.
|
|
|
|
// Remove when https://github.com/webpack/webpack/issues/2390 is fixed.
|
|
|
|
function bailOnStatsError() {
|
|
|
|
this.plugin('done', (stats) => {
|
|
|
|
if (stats.compilation.errors && stats.compilation.errors.length) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(stats.compilation.errors);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-03-08 00:21:12 +03:00
|
|
|
],
|
|
|
|
resolve: {
|
2016-03-21 20:14:38 +03:00
|
|
|
alias: {
|
2018-08-28 22:53:18 +03:00
|
|
|
normalize: 'normalize.css/normalize.css',
|
2017-05-23 00:02:23 +03:00
|
|
|
tests: path.resolve('./tests'),
|
2016-03-21 20:14:38 +03:00
|
|
|
},
|
2018-06-27 18:51:33 +03:00
|
|
|
modules: [path.resolve('./src'), 'node_modules'],
|
2017-05-18 00:07:06 +03:00
|
|
|
extensions: ['.js', '.jsx'],
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
};
|