Skip to content

Commit

Permalink
fix: merge custom externals config correctly, supports array (#4429)
Browse files Browse the repository at this point in the history
closes #4413

(cherry picked from commit 348e36e)
  • Loading branch information
haoqunjiang committed Aug 21, 2019
1 parent a0e8a6a commit e79133b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
23 changes: 12 additions & 11 deletions packages/@vue/cli-service/lib/commands/build/resolveLibConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
config.optimization.minimize(false)
}

// externalize Vue in case user imports it
config
.externals({
...config.get('externals'),
vue: {
commonjs: 'vue',
commonjs2: 'vue',
root: 'Vue'
}
})

// inject demo page for umd
if (genHTML) {
const template = isVueEntry ? 'demo-lib.html' : 'demo-lib-js.html'
Expand Down Expand Up @@ -101,6 +90,18 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
}
}

// externalize Vue in case user imports it
rawConfig.externals = [
...(Array.isArray(rawConfig.externals) ? rawConfig.externals : [rawConfig.externals]),
{
vue: {
commonjs: 'vue',
commonjs2: 'vue',
root: 'Vue'
}
}
].filter(Boolean)

rawConfig.entry = {
[entryName]: realEntry
}
Expand Down
15 changes: 8 additions & 7 deletions packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ module.exports = (api, { target, entry, name }) => {
config.optimization.minimize(false)
}

// externalize Vue in case user imports it
config
.externals({
...config.get('externals'),
vue: 'Vue'
})

config
.plugin('web-component-options')
.use(require('webpack/lib/DefinePlugin'), [{
Expand Down Expand Up @@ -104,6 +97,14 @@ module.exports = (api, { target, entry, name }) => {

const rawConfig = api.resolveWebpackConfig(config)

// externalize Vue in case user imports it
rawConfig.externals = [
...(Array.isArray(rawConfig.externals) ? rawConfig.externals : [rawConfig.externals]),
{
vue: 'Vue'
}
].filter(Boolean)

const entryName = `${libName}${minify ? `.min` : ``}`
rawConfig.entry = {
[entryName]: dynamicEntry
Expand Down

0 comments on commit e79133b

Please sign in to comment.