Skip to content

Commit 92e136a

Browse files
committed
fix: --target lib/wc should overwrite user entry/output
fix #1072
1 parent 203e069 commit 92e136a

File tree

3 files changed

+64
-48
lines changed

3 files changed

+64
-48
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
import Component from '~entry'
1+
;(function () {
2+
if (typeof window !== 'undefined') {
3+
let i
4+
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js$/))) {
5+
__webpack_public_path__ = i[1] // eslint-disable-line
6+
}
7+
} else {
8+
__webpack_public_path__ = '/' // eslint-disable-line
9+
}
10+
})()
211

3-
export default Component
12+
import mod from '~entry'
13+
export default mod
14+
export * from '~entry'

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,6 @@ module.exports = (api, { entry, name }, options) => {
1414
function genConfig (format, postfix = format, genHTML) {
1515
const config = api.resolveChainableWebpackConfig()
1616

17-
config.entryPoints.clear()
18-
const entryName = `${libName}.${postfix}`
19-
// set proxy entry for *.vue files
20-
if (/\.vue$/.test(entry)) {
21-
config
22-
.entry(entryName)
23-
.add(require.resolve('./entry-lib.js'))
24-
config.resolve
25-
.alias
26-
.set('~entry', api.resolve(entry))
27-
} else {
28-
config
29-
.entry(entryName)
30-
.add(api.resolve(entry))
31-
}
32-
33-
config.output
34-
.filename(`${entryName}.js`)
35-
.chunkFilename(`${entryName}.[id].js`)
36-
.library(libName)
37-
.libraryExport('default')
38-
.libraryTarget(format)
39-
// use relative publicPath so this can be deployed anywhere
40-
.publicPath('./')
41-
4217
// adjust css output name so they write to the same file
4318
if (options.css.extract !== false) {
4419
config
@@ -76,7 +51,32 @@ module.exports = (api, { entry, name }, options) => {
7651
}])
7752
}
7853

79-
return api.resolveWebpackConfig(config)
54+
// resolve entry/output
55+
const entryName = `${libName}.${postfix}`
56+
config.resolve
57+
.alias
58+
.set('~entry', api.resolve(entry))
59+
60+
// set entry/output after user configureWebpack hooks are applied
61+
const rawConfig = api.resolveWebpackConfig(config)
62+
63+
rawConfig.entry = {
64+
[entryName]: require.resolve('./entry-lib.js')
65+
}
66+
67+
Object.assign(rawConfig.output, {
68+
filename: `${entryName}.js`,
69+
chunkFilename: `${entryName}.[id].js`,
70+
library: libName,
71+
libraryExport: 'default',
72+
libraryTarget: format,
73+
// use dynamic publicPath so this can be deployed anywhere
74+
// the actual path will be determined at runtime by checking
75+
// document.currentScript.src.
76+
publicPath: ''
77+
})
78+
79+
return rawConfig
8080
}
8181

8282
return [

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ module.exports = (api, { target, entry, name }) => {
4343
function genConfig (minify, genHTML) {
4444
const config = api.resolveChainableWebpackConfig()
4545

46-
config.entryPoints.clear()
47-
const entryName = `${libName}${minify ? `.min` : ``}`
48-
49-
// set proxy entry for *.vue files
50-
config
51-
.entry(entryName)
52-
.add(dynamicEntry)
53-
config.resolve
54-
.alias
55-
.set('~root', api.resolve('.'))
56-
5746
// make sure not to transpile wc-wrapper
5847
config.module
5948
.rule('js')
@@ -65,14 +54,6 @@ module.exports = (api, { target, entry, name }) => {
6554
config.plugins.delete('uglify')
6655
}
6756

68-
config.output
69-
.filename(`${entryName}.js`)
70-
.chunkFilename(`${libName}.[id]${minify ? `.min` : ``}.js`)
71-
// use dynamic publicPath so this can be deployed anywhere
72-
// the actual path will be determined at runtime by checking
73-
// document.currentScript.src.
74-
.publicPath('')
75-
7657
// externalize Vue in case user imports it
7758
config
7859
.externals({
@@ -110,7 +91,31 @@ module.exports = (api, { target, entry, name }) => {
11091
}])
11192
}
11293

113-
return api.resolveWebpackConfig(config)
94+
// set entry/output last so it takes higher priority than user
95+
// configureWebpack hooks
96+
97+
// set proxy entry for *.vue files
98+
config.resolve
99+
.alias
100+
.set('~root', api.resolve('.'))
101+
102+
const rawConfig = api.resolveWebpackConfig(config)
103+
104+
const entryName = `${libName}${minify ? `.min` : ``}`
105+
rawConfig.entry = {
106+
[entryName]: dynamicEntry
107+
}
108+
109+
Object.assign(rawConfig.output, {
110+
filename: `${entryName}.js`,
111+
chunkFilename: `${libName}.[id]${minify ? `.min` : ``}.js`,
112+
// use dynamic publicPath so this can be deployed anywhere
113+
// the actual path will be determined at runtime by checking
114+
// document.currentScript.src.
115+
publicPath: ''
116+
})
117+
118+
return rawConfig
114119
}
115120

116121
return [

0 commit comments

Comments
 (0)