MCPcopy Index your code
hub / github.com/webpack/css-loader / apply

Method apply

test/helpers/get-json.js:108–141  ·  view source on GitHub ↗
(compiler)

Source from the content-addressed store, hash-verified

106
107 // eslint-disable-next-line class-methods-use-this
108 apply(compiler) {
109 compiler.hooks.emit.tap("CssModulesJsonPlugin", () => {
110 for (const [identifier, classNames] of Object.entries(replacementsMap)) {
111 const adjustedClassNames = replaceReplacements(classNames);
112
113 replacementsMap[identifier] = adjustedClassNames;
114
115 const [, resourcePath, localName] = identifier.match(IDENTIFIER_REGEX);
116
117 allExportsJson[resourcePath] = allExportsJson[resourcePath] || {};
118 allExportsJson[resourcePath][localName] = adjustedClassNames;
119 }
120
121 fs.writeFileSync(
122 this.options.filepath,
123 JSON.stringify(
124 // Make path to be relative to `context` (your project root)
125 Object.fromEntries(
126 Object.entries(allExportsJson).map((key) => {
127 // eslint-disable-next-line no-param-reassign
128 key[0] = path
129 .relative(compiler.context, key[0])
130 .replace(/\\/g, "/");
131
132 return key;
133 }),
134 ),
135 null,
136 2,
137 ),
138 "utf8",
139 );
140 });
141 }
142}
143
144module.exports = { getJSON, CssModulesJsonPlugin };

Callers 2

url-option.test.jsFile · 0.80

Calls 1

replaceReplacementsFunction · 0.85

Tested by

no test coverage detected