我有以下項目結構:錯誤:加載塊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時,出現錯誤,如問題所述。那麼是什麼導致了這個問題我還是不明白。 –