Skip to content

Commit 348e36e

Browse files
haoqunjiangpksunkara
authored andcommitted
fix: merge custom externals config correctly, supports array (#4429)
closes #4413
1 parent 94b07fb commit 348e36e

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

packages/@vue/cli-service/lib/commands/build/resolveLibConfig.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
5656
config.optimization.minimize(false)
5757
}
5858

59-
// externalize Vue in case user imports it
60-
config
61-
.externals({
62-
...config.get('externals'),
63-
vue: {
64-
commonjs: 'vue',
65-
commonjs2: 'vue',
66-
root: 'Vue'
67-
}
68-
})
69-
7059
// inject demo page for umd
7160
if (genHTML) {
7261
const template = isVueEntry ? 'demo-lib.html' : 'demo-lib-js.html'
@@ -104,6 +93,18 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
10493
}
10594
}
10695

96+
// externalize Vue in case user imports it
97+
rawConfig.externals = [
98+
...(Array.isArray(rawConfig.externals) ? rawConfig.externals : [rawConfig.externals]),
99+
{
100+
vue: {
101+
commonjs: 'vue',
102+
commonjs2: 'vue',
103+
root: 'Vue'
104+
}
105+
}
106+
].filter(Boolean)
107+
107108
rawConfig.entry = {
108109
[entryName]: realEntry
109110
}

packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ module.exports = (api, { target, entry, name }) => {
5454
config.optimization.minimize(false)
5555
}
5656

57-
// externalize Vue in case user imports it
58-
config
59-
.externals({
60-
...config.get('externals'),
61-
vue: 'Vue'
62-
})
63-
6457
config
6558
.plugin('web-component-options')
6659
.use(webpack.EnvironmentPlugin, [{
@@ -103,6 +96,14 @@ module.exports = (api, { target, entry, name }) => {
10396

10497
const rawConfig = api.resolveWebpackConfig(config)
10598

99+
// externalize Vue in case user imports it
100+
rawConfig.externals = [
101+
...(Array.isArray(rawConfig.externals) ? rawConfig.externals : [rawConfig.externals]),
102+
{
103+
vue: 'Vue'
104+
}
105+
].filter(Boolean)
106+
106107
const entryName = `${libName}${minify ? `.min` : ``}`
107108
rawConfig.entry = {
108109
[entryName]: dynamicEntry

0 commit comments

Comments
 (0)