forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.config.babel.js
89 lines (84 loc) · 2.83 KB
/
webpack.prod.config.babel.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-disable max-len, import/no-extraneous-dependencies */
import path from 'path';
import config from 'config';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import SriPlugin from 'webpack-subresource-integrity';
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import SriDataPlugin from './src/core/server/sriDataPlugin';
import { getPlugins, getRules } from './webpack-common';
import webpackIsomorphicToolsConfig from './src/core/server/webpack-isomorphic-tools-config';
const appName = config.get('appName');
const appsBuildList = appName ? [appName] : config.get('validAppNames');
const entryPoints = {};
for (const app of appsBuildList) {
entryPoints[app] = `${app}/client`;
}
export default {
devtool: 'source-map',
context: path.resolve(__dirname),
entry: entryPoints,
output: {
crossOriginLoading: 'anonymous',
path: path.join(__dirname, 'dist'),
filename: '[name]-[chunkhash].js',
chunkFilename: '[name]-[chunkhash].js',
publicPath: config.has('staticHost') ? `${config.get('staticHost')}/` : '/',
},
module: {
rules: getRules(),
},
node: {
// This allows us to use `__filename` in our code base, for instance to
// have unique names in the error handlers.
__filename: true,
},
plugins: [
...getPlugins(),
new ExtractTextPlugin({
filename: '[name]-[contenthash].css',
allChunks: true,
}),
// optimizations
new UglifyJsPlugin({
// Even though devtool is set to source-map, this must be true to output source maps:
sourceMap: true,
// 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,
},
},
}),
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig),
new SriPlugin({ hashFuncNames: ['sha512'] }),
new SriDataPlugin({
saveAs: path.join(__dirname, 'dist', 'sri.json'),
}),
// 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);
}
});
},
],
resolve: {
alias: {
normalize: 'normalize.css/normalize.css',
tests: path.resolve('./tests'),
},
modules: [path.resolve('./src'), 'node_modules'],
extensions: ['.js', '.jsx'],
},
};