DependencyTemplate.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @import { ReplaceSource } from "webpack-sources" */
  7. /** @import ChunkGraph from "./ChunkGraph" */
  8. /** @import CodeGenerationResults from "./CodeGenerationResults" */
  9. /** @import ConcatenationScope from "./ConcatenationScope" */
  10. /** @import Dependency from "./Dependency" */
  11. /** @import DependencyTemplates from "./DependencyTemplates" */
  12. /** @import { GenerateContext } from "./Generator" */
  13. /** @import Module, { RuntimeRequirements } from "./Module" */
  14. /** @import ModuleGraph from "./ModuleGraph" */
  15. /** @import RuntimeTemplate from "./RuntimeTemplate" */
  16. /** @import { RuntimeSpec } from "./util/runtime" */
  17. /**
  18. * Defines the init fragment type used by this module.
  19. * @template T
  20. * @typedef {import("./InitFragment")<T>} InitFragment
  21. */
  22. /**
  23. * Defines the dependency template context type used by this module.
  24. * @typedef {object} DependencyTemplateContext
  25. * @property {RuntimeTemplate} runtimeTemplate the runtime template
  26. * @property {DependencyTemplates} dependencyTemplates the dependency templates
  27. * @property {ModuleGraph} moduleGraph the module graph
  28. * @property {ChunkGraph} chunkGraph the chunk graph
  29. * @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
  30. * @property {Module} module current module
  31. * @property {RuntimeSpec} runtime current runtimes, for which code is generated
  32. * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
  33. * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
  34. * @property {CodeGenerationResults} codeGenerationResults the code generation results
  35. * @property {InitFragment<GenerateContext>[]} chunkInitFragments chunkInitFragments
  36. */
  37. /**
  38. * Defines the css dependency template context extras type used by this module.
  39. * @typedef {object} CssDependencyTemplateContextExtras
  40. * @property {CssData} cssData the css exports data
  41. * @property {string} type the css exports data
  42. */
  43. /**
  44. * Defines the css data type used by this module.
  45. * @typedef {object} CssData
  46. * @property {boolean} esModule whether export __esModule
  47. * @property {Map<string, string>} exports the css exports
  48. * @property {Map<string, { line: number, column: number }>=} exportLocs source position (line is 1-based, column is 0-based) of each export's defining identifier in the original CSS, used to emit fine-grained JS-to-CSS source mappings
  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("./errors/AbstractMethodError");
  63. throw new AbstractMethodError();
  64. }
  65. }
  66. module.exports = DependencyTemplate;