0

我的动态导入有什么问题?为什么它会添加错误的路径?

这行代码在 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',
},
4

0 回答 0