-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-webpack.config.js
52 lines (42 loc) · 1.34 KB
/
custom-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
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
let localCanisters, prodCanisters, canisters;
function initCanisterIds() {
try {
localCanisters = require(path.resolve(".dfx", "local", "canister_ids.json"));
} catch (error) {
console.log("No local canister_ids.json found. Continuing production");
}
try {
prodCanisters = require(path.resolve("canister_ids.json"));
} catch (error) {
console.log("No production canister_ids.json found. Continuing with local");
}
const network =
process.env.DFX_NETWORK ||
(process.env.NODE_ENV === "production" ? "ic" : "local");
canisters = network === "local" ? localCanisters : prodCanisters;
for (const canister in canisters) {
process.env[canister.toUpperCase() + "_CANISTER_ID"] =
canisters[canister][network];
}
}
initCanisterIds();
const isDevelopment = process.env.NODE_ENV !== "production";
module.exports = {
node: { global: true },
optimization: {
minimize: !isDevelopment,
minimizer: [new TerserPlugin()],
},
plugins: [
new webpack.EnvironmentPlugin({
COUNTER_CANISTER_ID: canisters["counter"]
}),
new webpack.ProvidePlugin({
Buffer: [require.resolve("buffer/"), "Buffer"],
process: require.resolve("process/browser"),
}),
],
};