CssImportDependency.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Ivan Kopeykin @vankop
  4. */
  5. "use strict";
  6. const makeSerializable = require("../util/makeSerializable");
  7. const ModuleDependency = require("./ModuleDependency");
  8. /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
  9. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  10. /** @typedef {import("../Dependency")} Dependency */
  11. /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
  12. /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
  13. /** @typedef {import("../Module")} Module */
  14. /** @typedef {import("../ModuleGraph")} ModuleGraph */
  15. /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
  16. /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
  17. /** @typedef {import("../util/Hash")} Hash */
  18. /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
  19. class CssImportDependency extends ModuleDependency {
  20. /**
  21. * @param {string} request request
  22. * @param {[number, number]} range range of the argument
  23. * @param {string | undefined} supports list of supports conditions
  24. * @param {string | undefined} media list of media conditions
  25. */
  26. constructor(request, range, supports, media) {
  27. super(request);
  28. this.range = range;
  29. this.supports = supports;
  30. this.media = media;
  31. }
  32. get type() {
  33. return "css @import";
  34. }
  35. get category() {
  36. return "css-import";
  37. }
  38. /**
  39. * @param {string} context context directory
  40. * @returns {Module} a module
  41. */
  42. createIgnoredModule(context) {
  43. return null;
  44. }
  45. }
  46. CssImportDependency.Template = class CssImportDependencyTemplate extends (
  47. ModuleDependency.Template
  48. ) {
  49. /**
  50. * @param {Dependency} dependency the dependency for which the template should be applied
  51. * @param {ReplaceSource} source the current replace source which can be modified
  52. * @param {DependencyTemplateContext} templateContext the context object
  53. * @returns {void}
  54. */
  55. apply(dependency, source, templateContext) {
  56. const dep = /** @type {CssImportDependency} */ (dependency);
  57. source.replace(dep.range[0], dep.range[1] - 1, "");
  58. }
  59. };
  60. makeSerializable(
  61. CssImportDependency,
  62. "webpack/lib/dependencies/CssImportDependency"
  63. );
  64. module.exports = CssImportDependency;