UNPKG

2.06 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8const makeSerializable = require("../util/makeSerializable");
9const NullDependency = require("./NullDependency");
10
11/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12/** @typedef {import("../Dependency")} Dependency */
13/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
15/** @typedef {import("../ModuleGraph")} ModuleGraph */
16
17class CssExportDependency extends NullDependency {
18 /**
19 * @param {string} name name
20 * @param {string} value value
21 */
22 constructor(name, value) {
23 super();
24 this.name = name;
25 this.value = value;
26 }
27
28 get type() {
29 return "css :export";
30 }
31
32 /**
33 * Returns the exported names
34 * @param {ModuleGraph} moduleGraph module graph
35 * @returns {ExportsSpec | undefined} export names
36 */
37 getExports(moduleGraph) {
38 const name = this.name;
39 return {
40 exports: [
41 {
42 name,
43 canMangle: true
44 }
45 ],
46 dependencies: undefined
47 };
48 }
49
50 serialize(context) {
51 const { write } = context;
52 write(this.name);
53 write(this.value);
54 super.serialize(context);
55 }
56
57 deserialize(context) {
58 const { read } = context;
59 this.name = read();
60 this.value = read();
61 super.deserialize(context);
62 }
63}
64
65CssExportDependency.Template = class CssExportDependencyTemplate extends (
66 NullDependency.Template
67) {
68 /**
69 * @param {Dependency} dependency the dependency for which the template should be applied
70 * @param {ReplaceSource} source the current replace source which can be modified
71 * @param {DependencyTemplateContext} templateContext the context object
72 * @returns {void}
73 */
74 apply(dependency, source, { cssExports }) {
75 const dep = /** @type {CssExportDependency} */ (dependency);
76 cssExports.set(dep.name, dep.value);
77 }
78};
79
80makeSerializable(
81 CssExportDependency,
82 "webpack/lib/dependencies/CssExportDependency"
83);
84
85module.exports = CssExportDependency;