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

80 строки
2.6 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

/* eslint-disable max-len, no-console, import/no-extraneous-dependencies */
2016-03-08 00:21:12 +03:00
import path from 'path';
import config from 'config';
2016-03-08 00:21:12 +03:00
import webpack from 'webpack';
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';
import webpackConfig from './webpack.prod.config.babel';
import webpackIsomorphicToolsConfig from './src/amo/server/webpack-isomorphic-tools-config';
import { WEBPACK_ENTRYPOINT } from './src/amo/constants';
const localDevelopment = config.util.getEnv('NODE_ENV') === 'development';
2018-06-27 18:51:33 +03:00
const webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(
webpackIsomorphicToolsConfig,
);
2016-03-23 19:25:07 +03:00
const babelConfig = require('./babel.config');
2016-03-23 19:25:07 +03:00
const babelPlugins = babelConfig.plugins || [];
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 = {
...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
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',
devtool: 'cheap-module-source-map',
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,
filename: '[name]-[contenthash].js',
chunkFilename: '[name]-[contenthash].js',
// We need to remove the protocol because of `yarn amo:dev-https`.
publicPath: config.get('staticPath'),
2019-08-26 13:10:49 +03:00
},
2016-03-08 00:21:12 +03:00
module: {
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.
//
// 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(),
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
};