When setting the path that webpack will use at runtime, how would this work? Here's my basic setup in terms of the generated html:
then in my main entry script:
window.webpack_public_path = window.resourceBaseUrl;
I tried the following as well:
just setting webpack_public_path in a script tag in the generated html
both before and after the bundle script tag
So how should I be setting `webpack_public_path ?
The only way I've got it working is by setting _webpack_require.p in my main entry file.
publicPath可以更改加载的资源路径,但是如果需要更改runtime开发环境下的脚本资源加载,就需要用到
__webpack_public_path__
Example of setting webpack public path at runtime:StackOverflow - DEMO
webpack output.publicPath 如何动态配置地址
// JS脚本 // 入口文件加载之前 //获取 meta 元素 var $path = document.querySelector('meta[name="AppPublic"]'); //如果该 meta 元素存在,则获取其 content 的路径 //如果该 meta 元素不存在,则为本地路径 webpack_public_path = $path ? $path.getAttribute('content')+'/app/js/' : '/'; //从该参数的使用上可以了解到,上面 meta 元素,本地可以不添加 //js获取不到执行本地环境路径,js获取成功则配置具体环境路径