UI for Zipcoin Blue

DllReferencePlugin.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
  7. const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
  8. const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
  9. const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
  10. const NullFactory = require("./NullFactory");
  11. class DllReferencePlugin {
  12. constructor(options) {
  13. this.options = options;
  14. }
  15. apply(compiler) {
  16. compiler.plugin("compilation", (compilation, params) => {
  17. const normalModuleFactory = params.normalModuleFactory;
  18. compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory);
  19. compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory());
  20. });
  21. compiler.plugin("before-compile", (params, callback) => {
  22. const manifest = this.options.manifest;
  23. if(typeof manifest === "string") {
  24. params.compilationDependencies.push(manifest);
  25. compiler.inputFileSystem.readFile(manifest, function(err, result) {
  26. if(err) return callback(err);
  27. params["dll reference " + manifest] = JSON.parse(result.toString("utf-8"));
  28. return callback();
  29. });
  30. } else {
  31. return callback();
  32. }
  33. });
  34. compiler.plugin("compile", (params) => {
  35. let manifest = this.options.manifest;
  36. if(typeof manifest === "string") {
  37. manifest = params["dll reference " + manifest];
  38. }
  39. const name = this.options.name || manifest.name;
  40. const sourceType = this.options.sourceType || "var";
  41. const externals = {};
  42. const source = "dll-reference " + name;
  43. externals[source] = name;
  44. params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(sourceType, externals));
  45. params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin({
  46. source: source,
  47. type: this.options.type,
  48. scope: this.options.scope,
  49. context: this.options.context || compiler.options.context,
  50. content: this.options.content || manifest.content,
  51. extensions: this.options.extensions
  52. }));
  53. });
  54. }
  55. }
  56. module.exports = DllReferencePlugin;