-
Notifications
You must be signed in to change notification settings - Fork 40
/
config-overrides.js.deprecated
89 lines (77 loc) · 2.48 KB
/
config-overrides.js.deprecated
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
80
81
82
83
84
85
86
87
88
89
const webpack = require('webpack');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const smp = new SpeedMeasurePlugin();
const fs = require('fs'); // Adjusted to CommonJS
// for local sdk linking
let path = '';
let ModuleScopePlugin = '';
// to read and modify webpack config based on local sdk linking or production
let localSDKLinking = false;
const envpath = `./.localsdk.env`;
if (fs.existsSync(envpath)) {
const { parse } = require('envfile'); // Adjusted to CommonJS
const envData = fs.readFileSync(envpath, 'utf8');
const envObject = parse(envData);
if (envObject['ENFORCE_WEBPACK_LOCAL'] === 'TRUE') {
localSDKLinking = true;
}
}
if (localSDKLinking) {
path = require('path');
ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
}
module.exports = {
webpack: (config, env) => {
// DEV LOCAL SDK MODE STUFF
if (localSDKLinking) {
config.resolve.plugins = config.resolve.plugins.filter((plugin) => !(plugin instanceof ModuleScopePlugin));
config.resolve.alias = {
react: path.resolve('./node_modules/react'),
'react-dom': path.resolve('./node_modules/react-dom'),
};
}
// do stuff with the webpack config...
config.resolve.fallback = {
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
child_process: false,
constants: require.resolve('constants-browserify'),
crypto: require.resolve('crypto-browserify'),
fs: false,
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
url: require.resolve('url'),
util: require.resolve('util/'),
stream: require.resolve('stream-browserify'),
zlib: require.resolve('browserify-zlib'),
};
config.resolve.extensions = [...config.resolve.extensions, '.ts', '.js'];
config.plugins = [
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
];
config.module.rules = [
...config.module.rules,
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
];
config.optimization.minimizer = [
new TerserPlugin({
exclude: /node_modules/,
parallel: true,
extractComments: true,
}),
];
return config;
},
};