Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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_Webpack - Fatal编程技术网

Javascript 在网页包插件中使用加载程序

Javascript 在网页包插件中使用加载程序,javascript,webpack,Javascript,Webpack,请澄清-这是一个关于编写 如何在网页包插件中使用网页包require MyPlugin.prototype.apply = function(compiler) { var self = this; compiler.plugin('emit', function(compilation, callback) { var file = 'example.css'; compilation.fileDependencies.push(file); var lo

请澄清-这是一个关于编写

如何在网页包插件中使用网页包
require

MyPlugin.prototype.apply = function(compiler) {
  var self = this;
  compiler.plugin('emit', function(compilation, callback) {
     var file = 'example.css';
     compilation.fileDependencies.push(file);
     var loaderResult = require('style!css!' + file); // <-- is there any way to make this possible?
  });
};
MyPlugin.prototype.apply=函数(编译器){
var self=这个;
plugin('emit',函数(编译,回调){
var file='example.css';
compilation.fileDependencies.push(文件);

var loaderResult=require('style!css!'+file);//经过一些搜索,我发现文本提取插件使用子编译来使用插件内部的编译器:

在下面的示例中,我使用
my loader
加载并编译
input.js
文件:

MyPlugin.prototype.apply = function(compiler) {
  compiler.plugin('make', 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);
  });
};

这实际上似乎并没有将input.js的内容推送到最后一个包中。我是否遗漏了什么?并且您实际上没有得到加载程序返回的数据:\