gpt4 book ai didi

javascript - Gulp webpack-dev-server : callback before bundle is finished

转载 作者:行者123 更新时间:2023-11-30 00:29:15 26 4
gpt4 key购买 nike

我正在尝试向 Gulp 中的 webpack-dev-server 模块添加回调。回调的目标是通知用户启动开发服务器的 URL。问题是在捆绑过程完成之前调用了回调。

如果我添加一个有效的固定超时,但这显然是不受欢迎的。

问题:我是否对回调结构做错了什么?为什么在捆绑完成之前调用它?

我在 Gulp 中的代码:

var server = new WebpackDevServer(webpack(devWebpackConfig), devServerConfig);
server.listen(options.devServerPort || 8080, 'localhost', function(err) {
if(err) {
console.error('[webpack-dev-server] failed to start:', err);
} else {
console.log('[webpack-dev-server] started:', 'Browse to http://localhost:'+ options.devServerPort +'/webpack-dev-server/');
}
});

当前输出:

[14:43:43] Finished 'dev' after 66 ms
[webpack-dev-server] started: Browse to http://localhost:8002/webpack-dev-server/
Hash: 638bdaa3201a4220c58e
Version: webpack 1.9.5
Time: 7315ms
Asset Size Chunks Chunk Names
c91905265455192ab6ea13d95c9edc63.woff 42.6 kB [emitted]
b09bad3c727751c808f224df00c208f8.woff 99.6 kB [emitted]
index.js 4.83 MB 0, 1 [emitted] styles, app
chunk {0} index.js (styles) 117 kB [rendered]
.....
webpack: bundle is now VALID.

我的期望:

[14:43:43] Finished 'dev' after 66 ms
Hash: 638bdaa3201a4220c58e
Version: webpack 1.9.5
Time: 7315ms
Asset Size Chunks Chunk Names
c91905265455192ab6ea13d95c9edc63.woff 42.6 kB [emitted]
b09bad3c727751c808f224df00c208f8.woff 99.6 kB [emitted]
index.js 4.83 MB 0, 1 [emitted] styles, app
chunk {0} index.js (styles) 117 kB [rendered]
...
webpack: bundle is now VALID.
[webpack-dev-server] started: Browse to http://localhost:8002/webpack-dev-server/

艾伦

最佳答案

尝试配置 devWebpackConfig 以使用 'done' plugin .

var compiler = webpack(devWebpackConfig);
compiler.plugin('done', function() {
console.log("started: Browse to http://localhost:8002/webpack-dev-server/")
});

var server = new WebpackDevServer(compiler);
server.listen(options.devServerPort || 8080, 'localhost', function(err) {
if (err) { console.error('[webpack-dev-server] failed to start:', err); }
});

关于javascript - Gulp webpack-dev-server : callback before bundle is finished,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30225866/

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