Skip to content

Commit c3d246f

Browse files
committed
fix: ensure dynamic publicPath is set early in lib/wc mode
fix #1253
1 parent 8b4a112 commit c3d246f

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
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-
})()
11-
1+
import './setPublicPath'
122
import mod from '~entry'
133
export default mod
144
export * from '~entry'

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports.resolveEntry = (prefix, libName, files, async) => {
4646
: files.map(file => createElement(prefix, file, file, async)).join('\n')
4747

4848
const content = `
49+
import './setPubicPath'
4950
import Vue from 'vue'
5051
import wrap from '@vue/web-component-wrapper'
5152
@@ -54,13 +55,6 @@ import 'css-loader/lib/css-base'
5455
import 'vue-style-loader/lib/addStylesShadow'
5556
import 'vue-loader/lib/runtime/componentNormalizer'
5657
57-
;(() => {
58-
let i
59-
if ((i = document.currentScript) && (i = i.src.match(/(.+\\/)[^/]+\\.js$/))) {
60-
__webpack_public_path__ = i[1]
61-
}
62-
})()
63-
6458
${elements}`.trim()
6559
fs.writeFileSync(filePath, content)
6660
return filePath
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is imported into lib/wc client bundles.
2+
3+
if (typeof window !== 'undefined') {
4+
let i
5+
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js$/))) {
6+
__webpack_public_path__ = i[1] // eslint-disable-line
7+
}
8+
}

0 commit comments

Comments
 (0)