fix: use dynamic publicPath for web component bundles (fix #949)

This commit is contained in:
Evan You
2018-03-06 15:06:03 -05:00
parent 2549257e21
commit f744040b50
2 changed files with 11 additions and 2 deletions

View File

@@ -68,8 +68,10 @@ module.exports = (api, { target, entry, name }) => {
config.output
.filename(`${entryName}.js`)
.chunkFilename(`${libName}.[id]${minify ? `.min` : ``}.js`)
// use relative publicPath so this can be deployed anywhere
.publicPath('./')
// use dynamic publicPath so this can be deployed anywhere
// the actual path will be determined at runtime by checking
// document.currentScript.src.
.publicPath('')
// externalize Vue in case user imports it
config

View File

@@ -33,6 +33,13 @@ import 'css-loader/lib/css-base'
import 'vue-style-loader/lib/addStylesShadow'
import 'vue-loader/lib/runtime/component-normalizer'
;(() => {
let i
if ((i = document.currentScript) && (i = i.src.match(/(.+\\/)[^/]+\\.js$/))) {
__webpack_public_path__ = i[1]
}
})()
${files.map(file => {
const { camelName, kebabName } = exports.fileToComponentName(prefix, file)
return async