使用 webpack 加載 HTML 頁面時出現 404 not found 錯誤。這些是我的配置。
Webpack.config.js:
const path = require('path');
module.exports= {
devServer: {
// contentBase
static : {
directory : path.join(__dirname, 'public/')
},
port: 3000,
// publicPath
devMiddleware:{
publicPath: 'https://localhost:3000/dist/',
},
// hotOnly
hot: 'only',
},
};
其他檔案配置在螢屏截圖上。webpack 服務器運行正常,但是當我嘗試加載頁面時出現此錯誤。請告訴我我錯在哪里。
其他檔案的螢屏截圖。 
uj5u.com熱心網友回復:
你有你index.html在你在正確的地方/public檔案夾?
來自webpack檔案:
要加載捆綁檔案,您需要
index.html在構建檔案夾中創建一個檔案,從中提供靜態檔案(--content-base 選項)。
或嘗試將其放入webpack.config.js:
devServer: {
historyApiFallback: true,
}
或者有時您可能需要像這樣指出您的historyApiFallback index.html檔案:
devServer: {
historyApiFallback:{
index:'build/index.html'
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391839.html
標籤:javascript 新产品经理 网络包 webpack-dev-server
