-
Notifications
You must be signed in to change notification settings - Fork 4
/
craco.config.js
79 lines (72 loc) · 2.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
webpack: {
alias: {
'@mui/styled-engine': '@mui/styled-engine-sc',
},
configure: (webpackConfig) => {
webpackConfig.resolve.fallback = {
...webpackConfig.resolve.fallback,
path: require.resolve('path-browserify'),
process: require.resolve('process/browser'), // Ensure process is aliased correctly
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
stream: require.resolve('stream-browserify'),
util: require.resolve('util'),
};
const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
({ constructor }) => constructor && constructor.name === 'ModuleScopePlugin'
);
webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
webpackConfig.plugins.push(
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
})
);
const jsRule = webpackConfig.module.rules.find(
(rule) => rule.oneOf && rule.oneOf.some((r) => r.test && r.test.toString().includes('js|jsx'))
);
if (jsRule) {
jsRule.oneOf.unshift({
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
});
}
webpackConfig.optimization = {
...webpackConfig.optimization,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
extractComments: false,
}),
],
};
return webpackConfig;
}
}
};