-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
84 lines (79 loc) · 2.21 KB
/
webpack.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
80
81
82
83
84
const path = require('path')
const createReactAppConfigFactory = require('react-scripts/config/webpack.config.js')
const createReactAppConfig = createReactAppConfigFactory(
process.env['NODE_ENV'] === 'production' ? 'production' : 'development'
)
// NOTE: export 2 configs:
// * server-side library, for usage in nodejs, with bundled React
// * client-side library, for importing into browser code, without bundled React (the consuming app provides the correct version)
const baseConfig = Object.assign({}, createReactAppConfig, {
output: Object.assign({}, createReactAppConfig.output, {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
// library: 'LeihsUI',
libraryTarget: 'umd'
}),
// DISABLE CHUNKS…
optimization: {}
})
const externalsConfig = {
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
}
}
}
module.exports = [
// all the bundles, server-side
{
...baseConfig,
target: 'node',
entry: {
main: './src/.emptyDummy.js', // ignored, but must be present so CRA works…
'leihs-ui-server-side': './src/server-side.js'
}
},
// all the bundles, client-side
{
...baseConfig,
target: 'web',
entry: {
main: './src/.emptyDummy.js', // ignored, but must be present so CRA works…
'leihs-ui-client-side': './src/client-side.js'
}
},
// all the bundles, with external react
{
...baseConfig,
target: 'web', // its the default, but just to be explicit…
entry: {
main: './src/.emptyDummy.js', // ignored, but must be present so CRA works…
'leihs-ui-client-side-external-react': './src/client-side.js'
},
...externalsConfig
},
// just the UI components lib
{
...baseConfig,
entry: {
main: './src/components-bundle.js'
},
output: Object.assign({}, baseConfig.output, {
path: path.resolve(__dirname, 'dist'),
filename: 'ui-components/index.js',
// library: "LeihsUI",
libraryExport: 'default',
libraryTarget: 'umd'
}),
...externalsConfig
}
]