我有以下项目结构:错误:加载块0失败。 - 的WebPack尝试加载0.js
|-mainFile.js
|-scripts -
|-Library1.js
|-Library2.js
库文件使用requirejs define([], function() {})
语法。
我因此投入webpack.config.js这样的:
module.exports = {
resolve: {
modules: [
path.resolve(__dirname, 'scripts'),
// The normal path
"node_modules"
]
},
/** ... **/
}
那么我这样做是mainFile.js
这是的WebPack切入点:
require(["Library1", "Library2"], function(Library1, Library2) { ... });
而且我得到这个错误:
GET http://localhost:3000/0.js [HTTP/1.1 404 Not Found 3ms]
Error: Loading chunk 0 failed.
Stack trace:
[email protected]://localhost:3000/player/webpack_build.js:100:24
webpack_build.js:146:52
The resource from “http://localhost:3000/0.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).[Learn More]
test_file.html Error: Loading chunk 0 failed.
因此,webpack试图加载一些0.js
文件。那应该是什么?
我需要的项目与'requirejs'兼容。这不可能吗? –
你可以使用任何模块格式与webpack(甚至混合它们)。只有导入没有代码分割,所以你可以在你的代码中使用'import'。如果某些第三方代码动态地导入了某些内容,则如果要将它们与webpack捆绑在一起,则必须提供/加载块。 –
但我正在使用与requirejs一起工作的正常requirejs代码。但是,当我运行webpack时,出现错误,如问题所述。那么是什么导致了这个问题我还是不明白。 –