fix: ensure dynamic publicPath is set early in lib/wc mode

fix #1253
This commit is contained in:
Evan You
2018-05-09 17:41:08 -04:00
parent 8b4a112b31
commit c3d246f7a2
3 changed files with 10 additions and 18 deletions
@@ -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'
@@ -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'
@@ -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
@@ -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
}
}