gpt4 book ai didi

javascript - 如何在内联模式下解决 webpack-dev-server 的 "Cannot GET/"

转载 作者:太空宇宙 更新时间:2023-11-04 15:55:11 26 4
gpt4 key购买 nike

当我在内联模式下使用 webpack-dev-server (版本 1.14.0)并访问 http://127.0.0.1:8080 时,结果是无法获取/

Error message screenshot

webpack.config.js中的配置是:

devServer: {
color: true,
historyApiFallback: false,
inline: true,
hot: true,
contentBase: assetsRoot
}

package.json 中的 npm 脚本是

"scripts": {
"dev": "webpack-dev-server",
"build": "webpack -p",
"clean": "node npm-scripts/del-build.script.js"
}

最佳答案

使用节点server.jsserver.js 代码:

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('../webpack.config');
console.log(config);
// 就是这么“复杂”!
// 往webpack的入口配置中加入 webpack-dev-server/client?http://localhost:8080/ 即可
for (var i of Object.keys(config.entry)){
config.entry[i].unshift("webpack-dev-server/client?http://localhost:8080/");
}
console.log(config.entry);
var compiler = webpack(config);
var server = new WebpackDevServer(compiler, {

});
server.listen(8080);

关于javascript - 如何在内联模式下解决 webpack-dev-server 的 "Cannot GET/",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42759792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com