forked from mozilla/testpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
177 lines (163 loc) · 4.84 KB
/
webpack.config.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* eslint-disable import/no-extraneous-dependencies */
const path = require("path");
const webpack = require("webpack");
const morgan = require("morgan");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const ContentPlugin = require("./frontend/lib/content");
const {
DevServerMiddleware,
DevServerHTTPSOptions
} = require("./frontend/lib/dev-server");
const packageJSON = require("./package.json");
const config = require("./frontend/config.js");
const RUN_ANALYZER = !!process.env.ANALYZER;
const NODE_ENV = process.env.NODE_ENV || "development";
const IS_DEV = NODE_ENV === "development";
const excludeVendorModules = [
"babel-polyfill",
"fluent",
"fluent-langneg",
"fluent-react",
"cldr-core"
];
const includeVendorModules = [
"babel-polyfill/browser",
"fluent/compat",
"fluent-langneg/compat",
"fluent-react/compat",
"cldr-core/supplemental/likelySubtags.json",
"html-react-parser/lib/dom-to-react",
"querystring"
];
const vendorModules = Object.keys(packageJSON.dependencies)
.filter(name => excludeVendorModules.indexOf(name) < 0)
.concat(includeVendorModules);
const extractSass = new ExtractTextPlugin({
// TODO: Take over filename hashing once gulp stops doing rev-assets
// filename: "[name].[contenthash].css"
filename: "[name].css"
});
const plugins = [
new webpack.DefinePlugin({
"process.env.NODE_ENV": `"${NODE_ENV}"`,
"process.env.ENABLE_DEV_LOCALES": process.env.ENABLE_DEV_LOCALE || 0,
"process.env.ENABLE_DEV_CONTENT": process.env.ENABLE_DEV_CONTENT || 0
}),
new CopyWebpackPlugin([
{ from: "./addon/*.xpi", to: "static/"},
{ context: "./locales", from: "**/*", to: "static/locales/" },
{ context: "./frontend/src/images", from: "**/*", to: "static/images/" }
]),
ContentPlugin(),
new WriteFilePlugin(),
// Include only moment locale modules that match AVAILABLE_LOCALES
new webpack.ContextReplacementPlugin(
/moment[\/\\]locale$/, // eslint-disable-line no-useless-escape
new RegExp(config.AVAILABLE_LOCALES.replace(/,/g, "|"))
),
new webpack.optimize.CommonsChunkPlugin("static/app/vendor"),
extractSass
];
if (!IS_DEV) {
plugins.push(
new UglifyJSPlugin({
parallel: true,
sourceMap: true
})
);
}
if (RUN_ANALYZER) {
plugins.push(new BundleAnalyzerPlugin({
analyzerPort: 9888 // Changed because extension auto-installer squats 8888
}));
}
module.exports = {
entry: {
"static/app/app": "./frontend/src/app/index.js",
"static/app/vendor": vendorModules,
"static/scripts/legal": "./frontend/src/scripts/legal.js",
"static/scripts/locale": "./frontend/src/scripts/locale.js"
},
output: {
path: path.resolve(__dirname, "frontend/build"),
// TODO: Take over filename hashing once gulp stops doing rev-assets
// filename: "[name].[hash].js"
filename: "[name].js"
},
node: {
crypto: false
},
stats: {
warningsFilter: warning => {
// seedrandom has a known complaint about missing optional crypto dep
if (warning.includes("seedrandom.js") &&
warning.includes("crypto")) { return true; }
// UglifyJs reports a lot of un-actionable warnings from vendor modules
if (warning.includes("static/app/vendor.js from UglifyJs")) { return true; }
return false;
}
},
devServer: {
port: process.env.PORT || 8000,
allowedHosts: ["example.com"],
publicPath: "/",
contentBase: path.join(__dirname, "frontend/build"),
index: "index.html",
before: app => {
app.use(morgan("dev"));
app.use(DevServerMiddleware);
},
https: { ...DevServerHTTPSOptions }
},
devtool: "source-map",
resolve: {
extensions: [".js", ".jsx"]
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: "babel-loader"
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
{ loader: "css-loader" },
{ loader: "postcss-loader" },
{ loader: "sass-loader" }
],
// use style-loader in development
fallback: "style-loader"
})
},
{
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
{
loader: "file-loader",
options: {
hash: "sha512",
digest: "hex",
publicPath: "/",
outputPath: "static/app/images/",
name: "[name]-[hash].[ext]"
}
},
{
loader: "image-webpack-loader",
options: {
bypassOnDebug: true
}
}
]
}
]
},
plugins
};