DependencyTemplate.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  7. /** @typedef {import("./ChunkGraph")} ChunkGraph */
  8. /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
  9. /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
  10. /** @typedef {import("./Dependency")} Dependency */
  11. /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
  12. /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
  13. /** @typedef {import("./Generator").GenerateContext} GenerateContext */
  14. /** @typedef {import("./Module")} Module */
  15. /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
  16. /** @typedef {import("./ModuleGraph")} ModuleGraph */
  17. /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
  18. /**
  19. * Defines the init fragment type used by this module.
  20. * @template T
  21. * @typedef {import("./InitFragment")<T>} InitFragment
  22. */
  23. /**
  24. * Defines the dependency template context type used by this module.
  25. * @typedef {object} DependencyTemplateContext
  26. * @property {RuntimeTemplate} runtimeTemplate the runtime template
  27. * @property {DependencyTemplates} dependencyTemplates the dependency templates
  28. * @property {ModuleGraph} moduleGraph the module graph
  29. * @property {ChunkGraph} chunkGraph the chunk graph
  30. * @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
  31. * @property {Module} module current module
  32. * @property {RuntimeSpec} runtime current runtimes, for which code is generated
  33. * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
  34. * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
  35. * @property {CodeGenerationResults} codeGenerationResults the code generation results
  36. * @property {InitFragment<GenerateContext>[]} chunkInitFragments chunkInitFragments
  37. */
  38. /**
  39. * Defines the css dependency template context extras type used by this module.
  40. * @typedef {object} CssDependencyTemplateContextExtras
  41. * @property {CssData} cssData the css exports data
  42. * @property {string} type the css exports data
  43. */
  44. /**
  45. * Defines the css data type used by this module.
  46. * @typedef {object} CssData
  47. * @property {boolean} esModule whether export __esModule
  48. * @property {Map<string, string>} exports the css exports
  49. */
  50. /** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
  51. class DependencyTemplate {
  52. /* istanbul ignore next */
  53. /**
  54. * Applies the plugin by registering its hooks on the compiler.
  55. * @abstract
  56. * @param {Dependency} dependency the dependency for which the template should be applied
  57. * @param {ReplaceSource} source the current replace source which can be modified
  58. * @param {DependencyTemplateContext} templateContext the context object
  59. * @returns {void}
  60. */
  61. apply(dependency, source, templateContext) {
  62. const AbstractMethodError = require("./AbstractMethodError");
  63. throw new AbstractMethodError();
  64. }
  65. }
  66. module.exports = DependencyTemplate;