Skip to content

Commit

Permalink
fix: ensure dynamic publicPath is set early in lib/wc mode
Browse files Browse the repository at this point in the history
fix #1253
  • Loading branch information
yyx990803 committed May 9, 2018
1 parent 8b4a112 commit c3d246f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
12 changes: 1 addition & 11 deletions packages/@vue/cli-service/lib/commands/build/entry-lib.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
;(function () {
if (typeof window !== 'undefined') {
let i
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js$/))) {
__webpack_public_path__ = i[1] // eslint-disable-line
}
} else {
__webpack_public_path__ = '/' // eslint-disable-line
}
})()

import './setPublicPath'
import mod from '~entry'
export default mod
export * from '~entry'
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports.resolveEntry = (prefix, libName, files, async) => {
: files.map(file => createElement(prefix, file, file, async)).join('\n')

const content = `
import './setPubicPath'
import Vue from 'vue'
import wrap from '@vue/web-component-wrapper'
Expand All @@ -54,13 +55,6 @@ import 'css-loader/lib/css-base'
import 'vue-style-loader/lib/addStylesShadow'
import 'vue-loader/lib/runtime/componentNormalizer'
;(() => {
let i
if ((i = document.currentScript) && (i = i.src.match(/(.+\\/)[^/]+\\.js$/))) {
__webpack_public_path__ = i[1]
}
})()
${elements}`.trim()
fs.writeFileSync(filePath, content)
return filePath
Expand Down
8 changes: 8 additions & 0 deletions packages/@vue/cli-service/lib/commands/build/setPublicPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is imported into lib/wc client bundles.

if (typeof window !== 'undefined') {
let i
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js$/))) {
__webpack_public_path__ = i[1] // eslint-disable-line
}
}

0 comments on commit c3d246f

Please sign in to comment.