-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
61 lines (57 loc) · 1.64 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
const Config = require("./dfx.json");
const Path = require("path");
// Identify build output directory.
const output = ["defaults", "build", "output"].reduce((accum, x) => {
return accum && accum[x] ? accum[x] : null;
}, Config) || Path.join(".dfx", "local", "canisters");
// Identify canisters aliases.
const aliases = Object.entries(Config.canisters).reduce((accum, [name,]) => {
const outputRoot = Path.join(__dirname, output, name);
return {
...accum,
["ic:canisters/" + name]: Path.join(outputRoot, name + ".js"),
["ic:idl/" + name]: Path.join(outputRoot, name + ".did.js"),
};
}, {});
// Generate webpack configuration.
const generate = (name, info) => {
if (typeof info.frontend !== 'object') {
return;
};
const inputRoot = __dirname;
const outputRoot = Path.join(__dirname, output, name);
return {
entry: Path.join(inputRoot, info.frontend.entrypoint),
mode: "production",
module: {
rules: [
{
loader: "babel-loader",
options: {
presets: [
"@babel/preset-react",
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-namespace-from"
]
},
test: /\.(js|jsx)$/,
},
{ test: /\.(css)$/, use: ['style-loader','css-loader'] },
],
},
output: {
filename: "index.js",
path: Path.join(outputRoot, "assets"),
},
resolve: {
alias: aliases,
},
};
};
module.exports = [
...Object.entries(Config.canisters).map(([name, info]) => {
return generate(name, info);
}).filter(x => !!x),
];