2016-08-20 01:15:37 +03:00
|
|
|
/* eslint-disable max-len, no-console, import/no-extraneous-dependencies */
|
2016-03-08 00:21:12 +03:00
|
|
|
import path from 'path';
|
2016-08-20 01:15:37 +03:00
|
|
|
|
|
|
|
import config from 'config';
|
2016-03-08 00:21:12 +03:00
|
|
|
import webpack from 'webpack';
|
2016-08-20 01:15:37 +03:00
|
|
|
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
|
2016-03-08 00:21:12 +03:00
|
|
|
|
2017-05-18 00:07:06 +03:00
|
|
|
import { getPlugins, getRules } from './webpack-common';
|
2016-04-28 00:06:27 +03:00
|
|
|
import webpackConfig from './webpack.prod.config.babel';
|
2021-01-12 17:07:03 +03:00
|
|
|
import webpackIsomorphicToolsConfig from './src/amo/server/webpack-isomorphic-tools-config';
|
|
|
|
import { WEBPACK_ENTRYPOINT } from './src/amo/constants';
|
2017-08-06 01:51:06 +03:00
|
|
|
|
2016-04-28 00:06:27 +03:00
|
|
|
const localDevelopment = config.util.getEnv('NODE_ENV') === 'development';
|
2016-03-22 01:11:54 +03:00
|
|
|
|
2018-06-27 18:51:33 +03:00
|
|
|
const webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(
|
|
|
|
webpackIsomorphicToolsConfig,
|
|
|
|
);
|
2016-03-23 19:25:07 +03:00
|
|
|
|
2022-06-16 20:04:53 +03:00
|
|
|
const babelConfig = require('./babel.config');
|
2016-03-23 19:25:07 +03:00
|
|
|
|
2022-06-16 20:04:53 +03:00
|
|
|
const babelPlugins = babelConfig.plugins || [];
|
2018-07-27 10:05:29 +03:00
|
|
|
const babelDevPlugins = ['react-hot-loader/babel'];
|
2016-03-23 19:25:07 +03:00
|
|
|
|
2019-08-26 13:10:49 +03:00
|
|
|
export const babelOptions = {
|
2022-06-16 20:04:53 +03:00
|
|
|
...babelConfig,
|
2018-06-27 18:51:33 +03:00
|
|
|
plugins: localDevelopment
|
|
|
|
? babelPlugins.concat(babelDevPlugins)
|
|
|
|
: babelPlugins,
|
2019-08-26 13:10:49 +03:00
|
|
|
};
|
2016-03-23 19:25:07 +03:00
|
|
|
|
2021-09-21 18:30:26 +03:00
|
|
|
const hmr = `webpack-hot-middleware/client?path=${config.get(
|
|
|
|
'staticPath',
|
|
|
|
)}__webpack_hmr`;
|
2016-04-22 19:42:57 +03:00
|
|
|
|
2020-12-01 23:22:49 +03:00
|
|
|
const entryPoints = { [WEBPACK_ENTRYPOINT]: [hmr, 'amo/client'] };
|
2016-04-22 19:42:57 +03:00
|
|
|
|
2018-11-20 21:19:46 +03:00
|
|
|
// We do not want the production optimization settings in development.
|
|
|
|
delete webpackConfig.optimization;
|
|
|
|
|
2019-08-26 13:10:49 +03:00
|
|
|
export default {
|
|
|
|
...webpackConfig,
|
2018-11-20 21:19:46 +03:00
|
|
|
mode: 'development',
|
2018-08-28 13:27:41 +03:00
|
|
|
devtool: 'cheap-module-source-map',
|
2016-04-28 00:06:27 +03:00
|
|
|
context: path.resolve(__dirname),
|
2016-04-22 19:42:57 +03:00
|
|
|
entry: entryPoints,
|
2019-08-26 13:10:49 +03:00
|
|
|
output: {
|
|
|
|
...webpackConfig.output,
|
2021-03-16 19:18:31 +03:00
|
|
|
filename: '[name]-[contenthash].js',
|
|
|
|
chunkFilename: '[name]-[contenthash].js',
|
2018-11-30 13:49:18 +03:00
|
|
|
// We need to remove the protocol because of `yarn amo:dev-https`.
|
2021-09-21 18:30:26 +03:00
|
|
|
publicPath: config.get('staticPath'),
|
2019-08-26 13:10:49 +03:00
|
|
|
},
|
2016-03-08 00:21:12 +03:00
|
|
|
module: {
|
2018-07-27 10:05:29 +03:00
|
|
|
rules: getRules({ babelOptions, bundleStylesWithJs: true }),
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
2017-05-18 00:07:06 +03:00
|
|
|
...getPlugins(),
|
2018-11-20 21:19:46 +03:00
|
|
|
// Load unminified React and Redux in development to get better error
|
|
|
|
// messages, because they use
|
|
|
|
// [Invariant](https://github.com/zertosh/invariant) which hides error
|
|
|
|
// messages in the production build.
|
2022-07-20 19:52:38 +03:00
|
|
|
//
|
|
|
|
// We can no longer load the React versions from /umd/ as it no longer
|
|
|
|
// exists.
|
|
|
|
// See https://github.com/mozilla/addons-frontend/issues/11737
|
|
|
|
// new webpack.NormalModuleReplacementPlugin(
|
|
|
|
// /^react$/,
|
|
|
|
// 'react/umd/react.development.js',
|
|
|
|
// ),
|
|
|
|
// new webpack.NormalModuleReplacementPlugin(
|
|
|
|
// /^react-dom$/,
|
|
|
|
// 'react-dom/umd/react-dom.development.js',
|
|
|
|
// ),
|
2018-06-27 18:51:33 +03:00
|
|
|
new webpack.NormalModuleReplacementPlugin(/^redux$/, 'redux/dist/redux.js'),
|
2016-03-08 00:21:12 +03:00
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
2022-04-25 21:56:37 +03:00
|
|
|
new webpack.IgnorePlugin({ resourceRegExp: /webpack-stats\.json$/ }),
|
2016-03-08 00:21:12 +03:00
|
|
|
webpackIsomorphicToolsPlugin.development(),
|
|
|
|
],
|
2019-08-26 13:10:49 +03:00
|
|
|
};
|