问题描述
这行代码在 Webpack 3 中有效,现在在 5 中不起作用:
loadCuisine() {
import(`@storage/json/cuisines/listofcuisines_${window.App.locale}.json`)
.then(this.addCuisines);
},
@storage
是别名:'@storage': path.join(__dirname,'storage/app/public'),
问题是,不知何故,动态 JSON 的路径是错误的。
错误说:
Uncaught (in promise) ChunkLoadError: Loading chunk storage_app_public_json_cuisines_listofcuisines_en_json Failed.
(missing: https://example.com/letscook/js/storage_app_public_json_cuisines_listofcuisines_en_json.65154af945c63aa7e43d.js)
如果您注意到它应该是 https://example.com/js/
而不是 https://example.com/letscook/js/
。
即使是源地图看起来也正确:
loadCuisine: function loadCuisine() {
__webpack_require__("./storage/app/public/json/cuisines lazy recursive ^\\.\\/listofcuisines_.*\\.json$")("./listofcuisines_".concat(window.App.locale,".json")).then(this.addCuisines);
},
知道为什么要放置子路径吗? (顺便说一下,错误发生在子页面 https://example.com/letscook
)
编辑:
这是在 webpack 中设置的一个选项:
output: {
publicPath: '',chunkFilename: 'js/[name].[chunkhash].js',},
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)