RequireIncludePlugin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const RequireIncludeDependency = require("./RequireIncludeDependency");
  7. const RequireIncludeDependencyParserPlugin = require("./RequireIncludeDependencyParserPlugin");
  8. class RequireIncludePlugin {
  9. apply(compiler) {
  10. compiler.hooks.compilation.tap(
  11. "RequireIncludePlugin",
  12. (compilation, { normalModuleFactory }) => {
  13. compilation.dependencyFactories.set(
  14. RequireIncludeDependency,
  15. normalModuleFactory
  16. );
  17. compilation.dependencyTemplates.set(
  18. RequireIncludeDependency,
  19. new RequireIncludeDependency.Template()
  20. );
  21. const handler = (parser, parserOptions) => {
  22. if (parserOptions.requireInclude === false) return;
  23. const warn = parserOptions.requireInclude === undefined;
  24. new RequireIncludeDependencyParserPlugin(warn).apply(parser);
  25. };
  26. normalModuleFactory.hooks.parser
  27. .for("javascript/auto")
  28. .tap("RequireIncludePlugin", handler);
  29. normalModuleFactory.hooks.parser
  30. .for("javascript/dynamic")
  31. .tap("RequireIncludePlugin", handler);
  32. }
  33. );
  34. }
  35. }
  36. module.exports = RequireIncludePlugin;