forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.config.babel.js
82 lines (69 loc) · 2.78 KB
/
webpack.dev.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
/* eslint-disable max-len, no-console, import/no-extraneous-dependencies */
import fs from 'fs';
import path from 'path';
import config from 'config';
import webpack from 'webpack';
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
import { getPlugins, getRules } from './webpack-common';
import webpackConfig from './webpack.prod.config.babel';
import webpackIsomorphicToolsConfig from './src/core/server/webpack-isomorphic-tools-config';
const localDevelopment = config.util.getEnv('NODE_ENV') === 'development';
const webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(
webpackIsomorphicToolsConfig,
);
const babelrc = fs.readFileSync('./.babelrc');
const babelrcObject = JSON.parse(babelrc);
const babelPlugins = babelrcObject.plugins || [];
const babelDevPlugins = ['react-hot-loader/babel'];
export const babelOptions = Object.assign({}, babelrcObject, {
plugins: localDevelopment
? babelPlugins.concat(babelDevPlugins)
: babelPlugins,
});
const webpackHost = config.get('webpackServerHost');
const webpackPort = config.get('webpackServerPort');
const assetsPath = path.resolve(__dirname, 'dist');
const hmr = `webpack-hot-middleware/client?path=//${webpackHost}:${webpackPort}/__webpack_hmr`;
const appName = config.get('appName');
const appsBuildList = appName ? [appName] : config.get('validAppNames');
const entryPoints = {};
for (const app of appsBuildList) {
entryPoints[app] = [hmr, `${app}/client`];
}
// We do not want the production optimization settings in development.
delete webpackConfig.optimization;
export default Object.assign({}, webpackConfig, {
mode: 'development',
devtool: 'cheap-module-source-map',
context: path.resolve(__dirname),
entry: entryPoints,
output: Object.assign({}, webpackConfig.output, {
path: assetsPath,
filename: '[name]-[hash].js',
chunkFilename: '[name]-[hash].js',
// We need to remove the protocol because of `yarn amo:dev-https`.
publicPath: `//${webpackHost}:${webpackPort}/`,
}),
module: {
rules: getRules({ babelOptions, bundleStylesWithJs: true }),
},
plugins: [
...getPlugins(),
// 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.
new webpack.NormalModuleReplacementPlugin(
/^react$/,
'react/umd/react.development.js',
),
new webpack.NormalModuleReplacementPlugin(
/^react-dom$/,
'react-dom/umd/react-dom.development.js',
),
new webpack.NormalModuleReplacementPlugin(/^redux$/, 'redux/dist/redux.js'),
new webpack.HotModuleReplacementPlugin(),
new webpack.IgnorePlugin(/webpack-stats\.json$/),
webpackIsomorphicToolsPlugin.development(),
],
});