-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebpack.config.js
More file actions
141 lines (137 loc) · 3.67 KB
/
webpack.config.js
File metadata and controls
141 lines (137 loc) · 3.67 KB
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
const webpack = require("webpack");
const path = require("path");
const packageJson = require("./package.json");
const GitRevisionPlugin = require("git-revision-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
// Export some data to the webpack build. See buildInfo.js.
const gitRevisionPlugin = new GitRevisionPlugin();
const definePlugin = new webpack.DefinePlugin({
__buildInfo__: {
version: JSON.stringify(packageJson.version),
gitVersion: JSON.stringify(gitRevisionPlugin.version()),
gitCommit: JSON.stringify(gitRevisionPlugin.commithash()),
},
});
function makeConfig({
target = "",
babelPresetEnvUseBuiltIns = false,
}) {
const babelPresetEnvTargets = (target === "legacy")
? {
"ie": "11",
}
: [
"last 2 versions",
"not ie < 999",
"not android < 999",
"not dead",
];
return {
mode: "development",
entry: {
// polyfill required by (at least) IE11
main: [
"whatwg-fetch",
"./webapp/main.js",
],
demo: [
"whatwg-fetch",
"./webapp/demo.js",
],
},
output: {
path: path.join(__dirname, "webapp", "dist"),
publicPath: "/webapp/dist/",
filename: `[name].${target ? target + "." : ""}js`,
},
devtool: "source-map",
plugins: [
definePlugin,
new BundleAnalyzerPlugin({
openAnalyzer: false,
generateStatsFile: true,
statsFilename: path.join(__dirname, "reports", (target ? target + "." : "") + "stats.json"),
analyzerMode: "static",
reportFilename: path.join(__dirname, "reports", (target ? target + "." : "") + "report.html"),
}),
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "initial",
},
},
},
},
module: {
rules: [
{
// .js or .jsx
test: /\.jsx?$/,
use: {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env", {
useBuiltIns: babelPresetEnvUseBuiltIns,
targets: babelPresetEnvTargets,
debug: true,
}],
"@babel/preset-react",
],
// transform-runtime required for things like Object.assign() for browsers that don't support that.
// rest-spread transform required for "valuelink"" module
plugins: [
"transform-class-properties",
],
},
},
},
{
test: /\.css$/,
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
},
],
},
{
// inline base64 URLs for <=8k images, direct URLs for the rest
test: /\.(png|jpg)$/,
loader: "url-loader?limit=8192",
},
],
},
devServer: {
// Until all the test resources are part of the harviewer-react project,
// use the original harviewer resources via proxy.
proxy: {
"/selenium": "http://harviewer.lan:49001",
},
},
resolveLoader: {
alias: {
"i18n": "amdi18n-loader",
},
},
};
}
module.exports = (env, options) => {
const prod = options && options.mode === "production";
const babelPresetEnvUseBuiltIns = prod ? "entry" : false;
return [
makeConfig({
babelPresetEnvUseBuiltIns,
}),
makeConfig({
target: "legacy",
babelPresetEnvUseBuiltIns,
}),
];
};