-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.webpack.config.js
More file actions
55 lines (37 loc) · 2.25 KB
/
Copy pathcustom.webpack.config.js
File metadata and controls
55 lines (37 loc) · 2.25 KB
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
const fs = require('fs')
const path = require('path');
// WebPack.config File
const fileConfig = 'node_modules/react-scripts/config/webpack.config.js'
if (fs.existsSync(fileConfig)) {
const configPath = path.resolve(__dirname, './package.json');
const json = JSON.parse(fs.readFileSync(configPath));
new Promise((resolve) => {
fs.readFile(fileConfig, 'utf8', function (err, data) {
if (err) {
return console.log(err)
}
resolve(data)
})
}).then((file) => {
//Exclude react from bundle
if (typeof json.buildConfig !== 'undefined' ) {
const externalsString = `externals: ${JSON.stringify(json.buildConfig.externals)},`;
const CodeAsString = `${externalsString}entry: paths.appIndexJs,`;
const result = file
.replace('static/js/[name].[contenthash:8].js', 'static/js/[name].js')
.replace('static/css/[name].[contenthash:8].css', 'static/css/[name].css')
.replace(/externals\:.*?entry\:\s*paths.appIndexJs,/, 'entry: paths.appIndexJs,')
// Do not package third-party frameworks into trunks
.replace(/minimize\:\s*[\s\S]*?minimizer\:/, `minimize: isEnvProduction, splitChunks:{chunks:"all",cacheGroups:{default:false,vendors:false,defaultVendors:{name:'main',chunks:'all',test:/.*/,priority:10,reuseExistingChunk:false}}},runtimeChunk:false, minimizer:`)
// alias
.replace(/alias:\s*{[\s\S]*?'react-native': 'react-native-web',/, `alias: {
'@': path.resolve(__dirname, paths.appSrc),
'react-native': 'react-native-web',`)
.replace(/entry\:\s*paths.appIndexJs,/, CodeAsString);
fs.writeFile(fileConfig, result, function (err) {
if (err) return console.log(err)
console.log('\x1b[36m%s\x1b[0m', `--> The webpack.config file was modifed!`);
})
}
})
}