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

89 строки
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';
import { SubresourceIntegrityPlugin } 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 CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
2016-04-25 23:07:36 +03:00
import SriDataPlugin from './src/amo/server/sriDataPlugin';
2017-05-18 00:07:06 +03:00
import { getPlugins, getRules } from './webpack-common';
import WebpackAssetsFontsPlugin from './src/amo/server/WebpackAssetsFontsPlugin';
import webpackIsomorphicToolsConfig from './src/amo/server/webpack-isomorphic-tools-config';
import { WEBPACK_ENTRYPOINT } from './src/amo/constants';
const DIST_DIR = path.join(__dirname, 'dist');
const STATIC_DIR = path.join(DIST_DIR, 'static');
2016-04-22 19:42:57 +03:00
2017-06-05 19:38:32 +03:00
export default {
bail: true,
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),
entry: { [WEBPACK_ENTRYPOINT]: 'amo/client' },
2016-03-08 00:21:12 +03:00
output: {
2017-05-18 00:07:06 +03:00
crossOriginLoading: 'anonymous',
// This is the path used to write the files on disk (which can be different from
// config.get('staticPath'), which is the path part of the URL the statics are
// served from).
// It needs to match the directory used by src/amo/middleware/staticAssets.js
path: STATIC_DIR,
filename: '[name]-[contenthash].js',
chunkFilename: '[name]-[contenthash].js',
// This is the path used to require files in the generated bundles.
publicPath: config.get('staticPath'),
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({
// This has been enabled by default in terser-webpack-plugin 2.0.0 but
// we were not using it before.
extractComments: false,
2018-11-20 21:19:46 +03:00
// 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 CssMinimizerPlugin(),
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({
filename: '[name]-[contenthash].css',
chunkFilename: '[name]-[contenthash].css',
2016-04-25 23:07:36 +03:00
}),
2016-03-08 00:21:12 +03:00
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig),
new WebpackAssetsFontsPlugin({
webpackAssetsFileName: 'webpack-assets.json',
}),
new SubresourceIntegrityPlugin({ hashFuncNames: ['sha512'] }),
new SriDataPlugin({ saveAs: path.join(DIST_DIR, 'sri.json') }),
2016-03-08 00:21:12 +03:00
],
resolve: {
2016-03-21 20:14:38 +03:00
alias: {
tests: path.resolve(__dirname, 'tests'),
2016-03-21 20:14:38 +03:00
},
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
2017-05-18 00:07:06 +03:00
extensions: ['.js', '.jsx'],
2016-03-08 00:21:12 +03:00
},
};