Open abargstaedt opened 4 years ago
https://github.com/vuejs/vue-cli/blob/ef548a7eca1884ad9db9d22a7dab0e540fd2b3a1/packages/%40vue/cli-service/lib/commands/build/resolveLibConfig.js#L114-L133 https://github.com/vuejs/vue-cli/blob/ef548a7eca1884ad9db9d22a7dab0e540fd2b3a1/packages/%40vue/cli-service/lib/commands/build/setPublicPath.js#L1-L15
const path = require('path')
const ASSET_PATH = '//localhost:4003/';
function PublicPathWebpackPlugin () {}
PublicPathWebpackPlugin.prototype.apply = function (compiler) {
compiler.hooks.entryOption.tap('PublicPathWebpackPlugin', (context, entry) => {
if (entry['module.common']) {
entry['module.common'] = path.resolve(__dirname, './src/main.js')
}
if (entry['module.umd']) {
entry['module.umd'] = path.resolve(__dirname, './src/main.js')
}
if (entry['module.umd.min']) {
entry['module.umd.min'] = path.resolve(__dirname, './src/main.js')
}
});
compiler.hooks.beforeRun.tap('PublicPathWebpackPlugin', (compiler) => {
compiler.options.output.publicPath = ASSET_PATH
})
}
module.exports = {
publicPath: ASSET_PATH,
configureWebpack (config) {
config.plugins.unshift(new PublicPathWebpackPlugin())
}
};
I was also having this problem when building a lib. I've confirmed that @lq111lq's plugin does work to inject this the public path as expected.
Thanks @lq111lq!
Even though publicPath
is ignored, using the property output.publicPath
from webpack config throws an error because this is forbidden.
publicPath
is not ignored, but rather overwritten in lines mentioned by lq111lq:
https://github.com/vuejs/vue-cli/blob/ef548a7eca1884ad9db9d22a7dab0e540fd2b3a1/packages/%40vue/cli-service/lib/commands/build/resolveLibConfig.js#L114-L133
It's a shame it hasn't been resolved after 4 years. It should be still possible to set publicPath
for libs, if someone wants to.
Version
4.1.1
Reproduction link
https://github.com/abargstaedt/poc-module-vue-cli
Environment info
Steps to reproduce
What is expected?
Logo PNG should be referenced to "//localhost:4003/img/logo.82b9c7a5.png"
What is actually happening?
Logo PNG is referenced to "img/logo.82b9c7a5.png"
We're aiming to host AMD/UMD modules on our web-space with the ability to load assets from the same location.