-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.webpack.js
185 lines (173 loc) · 5.04 KB
/
config.webpack.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* (c) 2010-present DEMOS plan GmbH.
*
* This file is part of the package demosplan,
* for more information see the license file.
*
* All rights reserved
*/
const merge = require('webpack-merge').default
const CopyWebpackPlugin = require('copy-webpack-plugin')
const DefinePlugin = require('webpack').DefinePlugin
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
const { config } = require('./client/fe/config/config') // All our configuration
const resolveAliases = require('./client/fe/webpack/resolveAliases').resolveAliases // To manage the @bundlePath Syntax
const resolveDir = require('./client/fe/webpack/util').resolveDir
const moduleRules = require('./client/fe/webpack/moduleRules').moduleRules
const bundleEntryPoints = require('./client/fe/webpack/bundleEntryPoints').bundleEntryPoints
const optimization = require('./client/fe/webpack/optimization').optimization
// Do not use destructuring as that may break the tooling on Windows
const { webpackDefaultPlugins, webpackDevOnlyPlugins, webpackProdOnlyPlugins } = require('./client/fe/webpack/plugins')
const baseConfig = {
mode: config.mode,
context: config.absoluteRoot,
output: {
filename: './[name].[contenthash:6].js',
chunkFilename: './[name].[contenthash:6].js',
clean: true
},
devtool: (config.isProduction) ? false : 'eval',
plugins: (() => {
let plugins = webpackDefaultPlugins
switch (config.mode) {
case 'development':
plugins = plugins.concat(webpackDevOnlyPlugins)
break
case 'testing':
break
case 'production':
plugins = plugins.concat(webpackProdOnlyPlugins)
break
default:
throw new Error('No config mode defined')
}
return plugins
})(),
cache: true,
performance: {
hints: false
},
module: {
rules: moduleRules
},
resolve: {
fallback: {
timers: require.resolve('timers-browserify'),
/*
* Prevent webpack from injecting useless setImmediate polyfill because Vue
* source contains it (although it only uses it if it's native).
*/
setImmediate: false,
/*
* Prevent webpack from injecting mocks to Node native modules
* that do not make sense for the client
*/
child_process: false,
dgram: false,
fs: false,
net: false,
tls: false,
buffer: false,
stream: false,
path: false
}
}
}
const bundlesConfig = merge(baseConfig, {
name: 'main',
entry: () => {
return {
style: config.stylesEntryPoint,
'style-public': config.publicStylesEntryPoint,
preflight: './client/css/preflight.css',
'demosplan-ui': './client/css/index.css',
...bundleEntryPoints(config.clientBundleGlob)
}
},
output: {
path: config.projectRoot + '/web/js/bundles',
publicPath: config.urlPathPrefix + '/js/bundles/'
},
devtool: (config.isProduction) ? false : 'eval',
resolve: {
fullySpecified: false,
extensions: ['...', '.js', '.vue', '.json', '.ts', '.tsx'],
alias: resolveAliases()
},
optimization: optimization(),
plugins: [
new DefinePlugin({
URL_PATH_PREFIX: JSON.stringify(config.urlPathPrefix) // Path prefix for dynamically generated urls
}),
new WebpackManifestPlugin({
fileName: '../../dplan.manifest.json'
})
]
})
const stylesConfig = merge(baseConfig, {
name: 'styles',
entry: () => {
return {
style: config.stylesEntryPoint,
'style-public': config.publicStylesEntryPoint,
'demosplan-ui': './client/css/index.css'
}
},
output: {
path: config.projectRoot + '/web/js/bundles',
publicPath: config.urlPathPrefix + '/js/bundles/',
clean: {
/*
* As the styles are emitted into the same output directory as
* JS assets, we want tp prevent the "clean" option from erasing
* everything. Instead, only style.[hash].js and style-public.[hash].js
* should be replaced.
* See https://webpack.js.org/configuration/output/#outputclean
*/
keep (asset) {
return !/style\.|style-public\./.test(asset)
}
}
},
devtool: (config.isProduction) ? false : 'eval',
optimization: optimization(),
plugins: [
new DefinePlugin({
URL_PATH_PREFIX: JSON.stringify(config.urlPathPrefix) // Path prefix for dynamically generated urls
}),
new WebpackManifestPlugin({
fileName: '../../styles.manifest.json'
})
]
})
const legacyBundlesConfig = {
mode: 'production',
name: 'legacy-bundles',
entry: resolveDir('client/js/legacy/legacy.js'),
output: {
path: config.projectRoot + '/web/js/legacy',
publicPath: config.urlPathPrefix + '/js/legacy/'
},
cache: true,
performance: {
hints: false
},
plugins: [
new WebpackManifestPlugin({
fileName: '../../legacy.manifest.json'
}),
new CopyWebpackPlugin({
patterns: [
{
from: resolveDir('client/js/legacy/'),
to: `${config.projectRoot}/web/js/legacy`
}
]
})
]
}
module.exports = [
bundlesConfig,
legacyBundlesConfig,
stylesConfig
]