-
Notifications
You must be signed in to change notification settings - Fork 352
/
webpack.config.cjs
93 lines (86 loc) · 1.87 KB
/
webpack.config.cjs
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
/* eslint-disable */
const pkg = require("./package.json");
const path = require("path");
const webpack = require("webpack");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const WebpackBar = require("webpackbar");
const {env} = process;
const config = {
entry: {
billboard: [
"./src/scss/billboard.scss",
"./src/index.ts"
]
},
output: {
path: path.resolve(__dirname, "dist"),
chunkFilename: "[name].bundle.js",
filename: "[name].js",
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "this",
publicPath: "/dist"
},
externals: ({context, request}, callback) => {
// every 'd3-*' import, will be externally required as their name except root as 'd3'
if (/^d3-/.test(request)) {
return callback(null, {
commonjs: request,
commonjs2: request,
amd: request,
root: "d3"
});
}
callback();
},
devtool: false,
resolve: {
extensions: [".ts", ".js"]
},
// https://webpack.js.org/migrate/5/#need-to-support-an-older-browser-like-ie-11
target: ["web", "es5"],
module: {
rules: [
{
test: /\.[jt]s$/,
loader: "esbuild-loader",
options: {
target: "es2015"
},
exclude: {
and: [/node_modules/],
not: [/(d3\-.*)$/, /internmap/]
}
},
{
test: /(\.[jt]s)$/,
loader: "string-replace-loader",
options: {
search: /__VERSION__/ig,
replace: env.VERSION || pkg.version
}
}
]
},
optimization: {
usedExports: true
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new WebpackBar()
],
node: false,
stats: "minimal",
mode: "none"
};
module.exports = () => {
let mode = "development";
if (env.NODE_ENV) {
mode = env.NODE_ENV;
}
env.ANALYZER && config.plugins.push(
new BundleAnalyzerPlugin()
);
mode === "packaged" && delete config.externals;
return require(`./config/webpack/${mode}.cjs`)(config, env);
};