3

The plugin compiles an additional asset during the emit phase:

MyPlugin.prototype.apply = function(compiler) {
  compiler.plugin('emit', function(compilation, callback) {
    var outputOptions = {
      filename: 'output.js',
      publicPath: compilation.outputOptions.publicPath
    };
    var childCompiler = compilation.createChildCompiler('MyPluginCompilation', outputOptions);
    childCompiler.apply(new NodeTemplatePlugin(outputOptions));
    childCompiler.apply(new LibraryTemplatePlugin('result', 'var'));
    childCompiler.apply(new NodeTargetPlugin());
    childCompiler.apply(new SingleEntryPlugin(this.context, 'my-loader!input.js'));
    childCompiler.runAsChild(callback);
  });
};

This works very well however webpack doesn't watch the specified 'input.js' file when using the webpack-dev-server.

How do I have to set up my webpack child compilation to recompile on file change?

Community
  • 1
  • 1
jantimon
  • 36,840
  • 23
  • 122
  • 185

1 Answers1

7

The watch is started at the after-compile step, which runs before emit, so your child compiler's file dependencies are never added to the list of files to watch.

You should use make instead of emit. It's the recommended interface for adding entries and modules to your compilation.

Alexandre Kirszenberg
  • 35,938
  • 10
  • 88
  • 72