forked from dfinity/motoko-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraco.config.js
58 lines (49 loc) · 1.59 KB
/
craco.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
const generateAliases = require("./src/config/generateAliases");
const path = require("path");
const webpack = require("webpack");
const aliases = generateAliases();
let canisterEnv;
function initCanisterIds() {
let localCanisters, prodCanisters, canisters;
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;
canisters = network === "local" ? localCanisters : prodCanisters;
for (const canister in canisters) {
const canisterName = canister.toUpperCase() + "_CANISTER_ID";
process.env[canisterName] = canisters[canister][network];
canisterEnv = {
...canisterEnv,
[canisterName]: canisters[canister][network],
};
}
}
initCanisterIds();
const overrideWebpackConfig = ({ webpackConfig }) => {
webpackConfig.resolve.alias = { ...webpackConfig.resolve.alias, ...aliases };
webpackConfig.resolve.plugins = webpackConfig.resolve.plugins.filter(
(plugin) =>
// Removes ModuleScopePlugin so `dfx-generated/` aliases work correctly
!Object.keys(plugin).includes("appSrcs")
);
webpackConfig.plugins = [
...webpackConfig.plugins,
new webpack.EnvironmentPlugin(canisterEnv),
];
return webpackConfig;
};
module.exports = {
plugins: [{ plugin: { overrideWebpackConfig } }],
};