UI for Zipcoin Blue

RequireEnsurePlugin.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
  7. const RequireEnsureDependency = require("./RequireEnsureDependency");
  8. const NullFactory = require("../NullFactory");
  9. const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
  10. const ParserHelpers = require("../ParserHelpers");
  11. class RequireEnsurePlugin {
  12. apply(compiler) {
  13. compiler.plugin("compilation", (compilation, params) => {
  14. const normalModuleFactory = params.normalModuleFactory;
  15. compilation.dependencyFactories.set(RequireEnsureItemDependency, normalModuleFactory);
  16. compilation.dependencyTemplates.set(RequireEnsureItemDependency, new RequireEnsureItemDependency.Template());
  17. compilation.dependencyFactories.set(RequireEnsureDependency, new NullFactory());
  18. compilation.dependencyTemplates.set(RequireEnsureDependency, new RequireEnsureDependency.Template());
  19. params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
  20. if(typeof parserOptions.requireEnsure !== "undefined" && !parserOptions.requireEnsure)
  21. return;
  22. parser.apply(new RequireEnsureDependenciesBlockParserPlugin());
  23. parser.plugin("evaluate typeof require.ensure", ParserHelpers.evaluateToString("function"));
  24. parser.plugin("typeof require.ensure", ParserHelpers.toConstantDependency(JSON.stringify("function")));
  25. });
  26. });
  27. }
  28. }
  29. module.exports = RequireEnsurePlugin;