Skip to content

Commit e79133b

Browse files
committed
fix: merge custom externals config correctly, supports array (#4429)
closes #4413 (cherry picked from commit 348e36e)
1 parent a0e8a6a commit e79133b

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
@@ -53,17 +53,6 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
5353
config.optimization.minimize(false)
5454
}
5555

56-
// externalize Vue in case user imports it
57-
config
58-
.externals({
59-
...config.get('externals'),
60-
vue: {
61-
commonjs: 'vue',
62-
commonjs2: 'vue',
63-
root: 'Vue'
64-
}
65-
})
66-
6756
// inject demo page for umd
6857
if (genHTML) {
6958
const template = isVueEntry ? 'demo-lib.html' : 'demo-lib-js.html'
@@ -101,6 +90,18 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
10190
}
10291
}
10392

93+
// externalize Vue in case user imports it
94+
rawConfig.externals = [
95+
...(Array.isArray(rawConfig.externals) ? rawConfig.externals : [rawConfig.externals]),
96+
{
97+
vue: {
98+
commonjs: 'vue',
99+
commonjs2: 'vue',
100+
root: 'Vue'
101+
}
102+
}
103+
].filter(Boolean)
104+
104105
rawConfig.entry = {
105106
[entryName]: realEntry
106107
}

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

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

56-
// externalize Vue in case user imports it
57-
config
58-
.externals({
59-
...config.get('externals'),
60-
vue: 'Vue'
61-
})
62-
6356
config
6457
.plugin('web-component-options')
6558
.use(require('webpack/lib/DefinePlugin'), [{
@@ -104,6 +97,14 @@ module.exports = (api, { target, entry, name }) => {
10497

10598
const rawConfig = api.resolveWebpackConfig(config)
10699

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

0 commit comments

Comments
 (0)