addons-frontend/webpack.prod.config.babel.js

104 строки
3.1 KiB
JavaScript
Исходник Обычный вид История

/* eslint-disable max-len, import/no-extraneous-dependencies */
2016-03-08 00:21:12 +03:00
import path from 'path';
import config from 'config';
2018-11-21 11:24:36 +03:00
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2017-05-18 00:07:06 +03:00
import SriPlugin from 'webpack-subresource-integrity';
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
2018-11-20 21:19:46 +03:00
import TerserPlugin from 'terser-webpack-plugin';
import OptimizeCssAssetsPlugin from 'optimize-css-assets-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';
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) {
entryPoints[app] = `${app}/client`;
2016-04-22 19:42:57 +03:00
}
2017-06-05 19:38:32 +03:00
export default {
2018-11-20 21:19:46 +03:00
mode: 'production',
2016-03-08 00:21:12 +03:00
devtool: 'source-map',
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',
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
},
node: {
// This allows us to use `__filename` in our code base, for instance to
// have unique names in the error handlers.
__filename: true,
},
2018-11-20 21:19:46 +03:00
optimization: {
minimizer: [
// We do not use UglifyJsPlugin because it does not work as intended with
// our config, but TerserPlugin is very similar.
new TerserPlugin({
cache: true,
parallel: true,
// 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
terserOptions: {
output: {
comments: false,
},
compress: {
drop_console: true,
},
},
}),
new OptimizeCssAssetsPlugin({
cssProcessorPluginOptions: {
preset: [
'default',
{
svgo: {
plugins: [
{
// There is a bug in this optimization.
// See https://github.com/mozilla/addons-frontend/issues/7191
convertPathData: false,
},
],
},
},
],
},
}),
2018-11-20 21:19:46 +03:00
],
},
2016-03-08 00:21:12 +03:00
plugins: [
2017-05-18 00:07:06 +03:00
...getPlugins(),
2018-11-21 11:24:36 +03:00
new MiniCssExtractPlugin({
2018-11-20 21:19:46 +03:00
filename: '[name]-[hash].css',
chunkFilename: '[name]-[hash].css',
2016-04-25 23:07:36 +03:00
}),
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'),
}),
2016-03-08 00:21:12 +03:00
],
resolve: {
2016-03-21 20:14:38 +03:00
alias: {
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
},
};