-
Notifications
You must be signed in to change notification settings - Fork 3
/
craco.config.js
42 lines (34 loc) · 1.62 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
module.exports = {
babel: process.env.REACT_APP_WDYR === "I_WANTED_TO" ? {
loaderOptions: (babelLoaderOptions) => {
console.log("🚨 Building with WDYR injected. This is terrible for perf. Only use for render profiling.");
const origBabelPresetCRAIndex = babelLoaderOptions.presets.findIndex((preset) => {
return preset[0].includes("babel-preset-react-app");
});
const origBabelPresetCRA = babelLoaderOptions.presets[origBabelPresetCRAIndex];
babelLoaderOptions.presets[origBabelPresetCRAIndex] = function overridenPresetCRA(api, opts, env) {
const babelPresetCRAResult = require(
origBabelPresetCRA[0]
)(api, origBabelPresetCRA[1], env);
babelPresetCRAResult.presets.forEach(preset => {
// detect @babel/preset-react with {development: true, runtime: 'automatic'}
if (!preset || !preset[1] || preset[1].runtime !== "automatic" || !preset[1].development) return;
preset[1].importSource = "@welldone-software/why-did-you-render";
});
return babelPresetCRAResult;
};
return babelLoaderOptions;
},
} : {},
webpack: {
configure: config => {
if (process.env.STAGING) {
config.mode = "development";
config.optimization.minimize = false;
config.optimization.minimizer = [];
console.log("I'm making a ghetto production build.");
}
return config;
}
}
};