-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.react4xp.js
58 lines (50 loc) · 1.81 KB
/
webpack.config.react4xp.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 path = require('path')
const WatcherTouchPlugin = require('./WatcherTouchPlugin')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = function (env, config) {
// This makes 'npm link' symlinks in node_modules work:
if (!config.resolve.alias) {
config.resolve.alias = {}
}
config.resolve.alias['/react4xp'] = path.resolve(__dirname, './src/main/resources/react4xp/')
config.resolve.symlinks = false
// config.plugins = [
// new BundleAnalyzerPlugin(),
// ]
// Dont bundle all node_modules import into one file
// config.optimization.splitChunks.chunks = 'all'
// delete config.optimization.splitChunks.cacheGroups.vendors
// Take these packages out of vendor.js and put them in their own file.
// These are big packages that are not used on every page, thus we let webpack only load them when needed.
const vendorSplits = [
'xss',
'highcharts',
'react-select',
'react-table',
'react-bootstrap',
'react-responsive',
'react-number-format',
]
vendorSplits.forEach((package) => {
const test = `/node_modules/${package}`
config.optimization.splitChunks.cacheGroups[package] = {
name: package + '-chunk',
enforce: true,
test: new RegExp(test),
chunks: 'all',
priority: 101, // higher than vendor.js (100)
}
})
config.target = ['web', 'es2020']
if (process.env.WATCH === 'true') {
config.plugins.push(new WatcherTouchPlugin())
config.watch = true
}
/*
Pro tip, Add:
process.env.NODE_ENV = 'development';
to the top of the function in node_modules/@enonic/react4xp/dist/webpack.config.globals.js
to get non-minified react in externals, so you can debug easier in the browser and XP terminal without getting minified react error
*/
return config
}