【发布时间】:2021-02-11 06:35:56
【问题描述】:
要求
我需要运行 webpack-dev-server 并等待服务器准备好提供页面。
解决方案
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: myConfig.output.publicPath,
hot: true,
historyApiFallback: true,
// It suppress error shown in console, so it has to be set to false.
quiet: false,
// It suppress everything except error, so it has to be set to false as well
// to see success build.
noInfo: false,
stats: {
// Config for minimal console.log mess.
assets: false,
colors: true,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false
}
}).listen(3000, '0.0.0.0', function(err) {
if(err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[webpack-dev-server]', 'http://0.0.0.0:3000/webpack-dev-server/index.html');
//this is to ensure that end to end test wouldn't start running until the server is ready
http.get({
hostname: '0.0.0.0',
port: 3000,
path: '/',
agent: false // create a new agent just for this one request
}, (/*res*/) => {
// Do stuff with response
done();
});
});
问题
在 Linux 上等待服务器准备就绪。在 Windows 上我得到一个异常,因为没有等待并且服务器没有准备好
C:\development\ucms-react>gulp webpack-dev-server [11:03:01] 需要 外部模块 babel-register [11:03:07] 使用 gulpfile C:\development\ucms-react\gulpfile.babel.js [11:03:07] 开始 'webpack-dev-server'... [11:03:07] [webpack-dev-server] http://0.0.0.0:3000/webpack-dev-server/index.html错误事件.js:141 投掷者; // 未处理的“错误”事件 ^
错误:连接 EADDRNOTAVAIL 0.0.0.0:3000 在 Object.exports._errnoException (util.js:907:11) 在exports._exceptionWithHostPort (util.js:930:20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)
C:\development\ucms-react>
我该如何解决这个问题?
【问题讨论】:
标签: javascript node.js webpack webpack-dev-server