forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.babel.js
134 lines (125 loc) · 4.25 KB
/
webpack.prod.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
132
133
134
/* eslint-disable max-len, import/no-extraneous-dependencies */
import path from 'path';
import autoprefixer from 'autoprefixer';
import config from 'config';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import SriStatsPlugin from 'sri-stats-webpack-plugin';
import webpack from 'webpack';
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
import { getClientConfig } from 'core/utils';
import webpackIsomorphicToolsConfig
from './src/core/server/webpack-isomorphic-tools-config';
const clientConfig = getClientConfig(config);
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] = `src/${app}/client`;
}
const settings = {
devtool: 'source-map',
context: path.resolve(__dirname),
progress: true,
entry: entryPoints,
output: {
path: path.join(__dirname, 'dist'),
filename: '[name]-[chunkhash].js',
chunkFilename: '[name]-[chunkhash].js',
publicPath: config.has('staticHost') ? `${config.get('staticHost')}/` : '/',
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css?importLoaders=2&sourceMap!postcss?outputStyle=expanded&sourceMap=true&sourceMapContents=true'),
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css?importLoaders=2&sourceMap!postcss!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true'),
}, {
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'),
// 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'),
// This allow us to exclude locales for other apps being built.
new webpack.ContextReplacementPlugin(
/locale$/,
new RegExp(`^\\.\\/.*?\\/${appName}\\.js$`)
),
new ExtractTextPlugin('[name]-[contenthash].css', { allChunks: true }),
new SriStatsPlugin({
algorithm: 'sha512',
write: true,
saveAs: path.join(__dirname, 'dist/sri.json'),
}),
// optimizations
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
},
}),
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig),
],
resolve: {
alias: {
'normalize.css': 'normalize.css/normalize.css',
},
root: [
path.resolve(__dirname),
path.resolve('./src'),
],
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.jsx'],
},
};
if (config.get('enablePostCssLoader')) {
settings.postcss = [
autoprefixer({ browsers: ['last 2 versions'] }),
];
}
export default settings;