Webpack插件看儿童编译

jan*_*mon 2 javascript node.js webpack

该插件在此阶段编译了一个额外的资产emit:

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);
  });
};
Run Code Online (Sandbox Code Playgroud)

这很好用,但webpack 'input.js'在使用时不会看到指定的文件webpack-dev-server.

如何设置我的webpack子编译以重新编译文件更改?

Ale*_*erg 5

手表在之前after-compile运行的步骤中启动,因此您的子编译器的文件依赖性永远不会添加到要监视的文件列表中. emit

你应该使用make而不是emit.它是用于向编辑中添加条目和模块的推荐界面.