Some way to know when webpack end with watch option enabled?
See original GitHub issueI need to know when my webpack task ends and it start to watch the files change, i tried by this way, without success.
gulp.task("pack", function() {
var stream = webpack({
output : {
filename : "bundle.js"
},
watch : true
});
stream.on("end", function() {
console.log("build end!");
});
return gulp.src("public/src/app/app.js").pipe(stream)
.pipe( gulp.dest("public/dist"));
});
When i run the task with gulp pack command, webpack start to watch but never emits the “end” event, instead of that, when i remove the watch option or set it to false, the “end” event is triggered as well.
There is some way to know when webpack start listen for changes, using watch = true?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Watch and WatchOptions | webpack
Watch and WatchOptions. Webpack can watch files and recompile whenever they change. This page explains how to enable this and a couple of...
Read more >Development | webpack
Using Watch Mode ... You can instruct webpack to "watch" all files within your dependency graph for changes. If one of these files...
Read more >Compiler Hooks | webpack
Executes a plugin during watch mode after a new compilation is triggered but before the compilation is actually started. Callback Parameters: compiler ...
Read more >DevServer - webpack
webpack -dev-server can be used to quickly develop an application. See the development guide to get started. This page describes the options that...
Read more >Command Line Interface - webpack
init, init|create|c|new|n [generation-path] [options], Initialize a new ... --watch-options-stdin, boolean, Stop watching when stdin stream has ended.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For my use I finally got this working relying on the native webpack watch (specified in the webpack config) and not using gulp.watch() calls to monitor my .js source files. The key for me was calling the gulp “task completed callback” cb() on only the first task iteration (tracked with taskNum variable) within the stats/done webpack callback.
Also below are pieces to load in the external webpack config, adding webpack watch mode if NODE_ENV = development. Also webpackStatsConfig can be changed to get different output options. Also a version that does not use webpack-stream that helped me get to a little better understanding of what was happening…though I’m not sure which is “better”. Big thanks to @shama for his work on this front.
As long as webpack runs in the same process, running it subsequent times will do incremental builds. So I assumed the
watch
option was for use without another watching library.You might trying passing an optional callback to
webpack(config, null, callback)
to know when it has compiled. It doesn’t end the stream on purpose withwatch: true
specified. That behavior was added in this PR https://github.com/shama/webpack-stream/pull/4, it looks purposeful but I can’t say why as I’m not a consumer of that use case.