Skip to content

Commit

Permalink
fix: merge custom externals config correctly, supports array (vuejs…
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang authored and pksunkara committed Aug 15, 2019
1 parent 94b07fb commit 348e36e
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 @@ -56,17 +56,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 @@ -104,6 +93,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 @@ -54,13 +54,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(webpack.EnvironmentPlugin, [{
Expand Down Expand Up @@ -103,6 +96,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 348e36e

Please sign in to comment.