diff --git a/packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js b/packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js index 0c5a65bbac..bb05a50545 100644 --- a/packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js +++ b/packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js @@ -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 diff --git a/packages/@vue/cli-service/lib/commands/build/resolveWcEntry.js b/packages/@vue/cli-service/lib/commands/build/resolveWcEntry.js index 82d9988535..7b70cfd44a 100644 --- a/packages/@vue/cli-service/lib/commands/build/resolveWcEntry.js +++ b/packages/@vue/cli-service/lib/commands/build/resolveWcEntry.js @@ -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