forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.config.babel.js
131 lines (117 loc) · 4.2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* 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 { getClientConfig } from 'core/utils';
import webpackConfig from './webpack.prod.config.babel';
import webpackIsomorphicToolsConfig
from './src/core/server/webpack-isomorphic-tools-config';
const clientConfig = getClientConfig(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-transform', {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
}],
}]];
const BABEL_QUERY = 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 = {};
// eslint-disable-next-line no-restricted-syntax
for (const app of appsBuildList) {
entryPoints[app] = [
hmr,
`src/${app}/client`,
];
}
export default Object.assign({}, webpackConfig, {
devtool: 'inline-source-map',
context: path.resolve(__dirname),
entry: entryPoints,
output: Object.assign({}, webpackConfig.output, {
path: assetsPath,
filename: '[name]-[hash].js',
chunkFilename: '[name]-[hash].js',
publicPath: `//${webpackHost}:${webpackPort}/`,
}),
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: BABEL_QUERY,
}, {
test: /\.css$/,
loader: 'style!css?importLoaders=2!postcss?outputStyle=expanded',
}, {
test: /\.scss$/,
loader: 'style!css?importLoaders=2!postcss!sass?outputStyle=expanded',
}, {
test: /\.svg$/,
loader: 'svg-url?limit=10000',
}, {
test: /\.jpg$/,
loader: 'url?limit=10000&mimetype=image/jpeg',
}, {
test: /\.png$/,
loader: 'url?limit=10000&mimetype=image/png',
}, {
test: /\.gif/,
loader: 'url?limit=10000&mimetype=image/gif',
}, {
test: /\.webm$/,
loader: 'url?limit=10000&mimetype=video/webm',
}, {
test: /\.mp4$/,
loader: 'url?limit=10000&mimetype=video/mp4',
}, {
test: /\.otf$/,
loader: 'url?limit=10000&mimetype=application/font-sfnt',
}, {
test: /\.woff$/,
loader: 'url?limit=10000&mimetype=application/font-woff',
}, {
test: /\.woff2$/,
loader: 'url?limit=10000&mimetype=application/font-woff2',
},
],
},
plugins: [
new webpack.DefinePlugin({
CLIENT_CONFIG: JSON.stringify(clientConfig),
'process.env.NODE_ENV': JSON.stringify('production'),
}),
// Replaces server config module with the subset clientConfig object.
new webpack.NormalModuleReplacementPlugin(/config$/, 'core/client/config.js'),
// Prevent locales with moment require calls from crashing
new webpack.NormalModuleReplacementPlugin(/\.\.\/moment$/, 'moment'),
// This allow us to exclude locales for other apps being built.
new webpack.ContextReplacementPlugin(
/locale$/,
new RegExp(`^\\.\\/.*?\\/${appName}\\.js$`)
),
// Substitutes client only config.
new webpack.NormalModuleReplacementPlugin(/core\/logger$/, 'core/client/logger.js'),
// Use the browser's window for window.
new webpack.NormalModuleReplacementPlugin(/core\/window/, 'core/browserWindow.js'),
new webpack.HotModuleReplacementPlugin(),
new webpack.IgnorePlugin(/webpack-stats\.json$/),
webpackIsomorphicToolsPlugin.development(),
],
});