問題描述
Webpack 在初始構建後不構建捆綁包 (Webpack not building bundle after initial build)
我遇到了一個我以前在使用 Webpack 時從未遇到過的問題。簡單地說 ‑ 我讓 webpack 監視我的反應文件並通過 webpack ‑‑watch
將其編譯成一個包。最初的編譯和構建效果很好,我可以看到變化。但是,出於某種原因,進行任何其他更改都不會使用更新更改構建捆綁包。您可以在 webpack running 的輸出中看到它
webpack 5.37.0 compiled successfully in 1243 ms
assets by status 1.14 MiB [cached] 1 asset
cached modules 1.07 MiB (javascript) 1.13 KiB (runtime) [cached] 39 modules
./public/src/components/home/components/HeaderInformation.jsx 608 bytes [built]
webpack 5.37.0 compiled successfully in 27 ms
assets by status 1.14 MiB [cached] 1 asset
cached modules 1.07 MiB (javascript) 1.13 KiB (runtime) [cached] 40 modules
webpack 5.37.0 compiled successfully in 19 ms
assets by status 1.14 MiB [cached] 1 asset
cached modules 1.07 MiB (javascript) 1.13 KiB (runtime) [cached] 40 modules
webpack 5.37.0 compiled successfully in 18 ms
到目前為止我發現的唯一解決方法是重新啟動 webpack 並告訴它再次觀看...不理想。我不知道我在這裡缺少什麼,因為我沒有看到任何錯誤,而且我在網絡上的搜索導致我沒有答案。對於上下文,這是我的 webpack.config 文件
module.exports = {
entry: __dirname + '/public/src/index.jsx',
mode: 'development',
module: {
rules: [
{
test: [/\.jsx$/],
exclude: /node_modules/,
use: {
loader: 'babel‑loader',
options: {
presets: ['@babel/preset‑react', '@babel/preset‑env']
}
}
}
]
},
output: {
filename: 'bundle.js',
path: __dirname + '/public/dist'
}
};
參考解法
方法 1:
I foolishly chose to ignore some warnings in the console of the application that I thought weren't relevant. DevTools failed to load SourceMap for webpack:///node_modules//…js.map HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
was the error I was seeing. Doing some reason lead me to here DevTools failed to load SourceMap for webpack:///node_modules//....js.map HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME. Adding in devtool: "eval‑cheap‑source‑map"
to the top of my webpack.config
fixed my issue.
(by jesuslovesu2baby、jesuslovesu2baby)