Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页包插件监视子编译_Javascript_Node.js_Webpack - Fatal编程技术网

Javascript 网页包插件监视子编译

Javascript 网页包插件监视子编译,javascript,node.js,webpack,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 childC

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);
  });
};
这非常有效,但是当使用
webpack dev server
时,webpack不会查看指定的
'input.js'
文件


我必须如何设置我的网页包子编译以在文件更改时重新编译?

监视在编译后的
步骤启动,该步骤在
发出
之前运行,因此您的子编译器的文件依赖项永远不会添加到要监视的文件列表中

您应该使用
make
而不是
emit
。它是向编译中添加条目和模块的工具