You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add getJSON option to output CSS modules mapping
This changeset adds a `getJSON` option to output CSS modules mappings to JSON.
This value can be a boolean or a function, and it employs similar logic to
[postcss-modules#getJSON](https://github.com/madyankin/postcss-modules?tab=readme-ov-file#saving-exported-classes) as a function.
This is particularly useful for SSR/SSG/templating languages when CSS modules mappings need to be present at build time.
Addresses [#988](#988).
Enables the outputting of the CSS modules mapping JSON. This can be omitted or set to a falsy value to disable any output.
1392
+
1393
+
###### `boolean`
1394
+
1395
+
Possible values:
1396
+
1397
+
-`true` - writes a JSON file next located in the same directory as the loaded resource file. For example, given a resource file located at /foo/bar/baz.css, this would write the CSS modules mapping JSON to /foo/bar/baz.css.json
exports[`"modules" option should invoke the custom getJSON function with getJSON as a function: result 1`] = `
1168
+
Array [
1169
+
Array [
1170
+
"./modules/getJSON/source.css",
1171
+
".RT7ktT7mB7tfBR25sJDZ {
1172
+
background-color: aliceblue;
1173
+
}
1174
+
1175
+
.IZmhTnK9CIeu6ww6Zjbv {
1176
+
background-color: burlywood;
1177
+
}
1178
+
1179
+
.PV11nPFlF7mzEgCXkQw4 {
1180
+
background-color: chartreuse;
1181
+
}
1182
+
1183
+
.d {
1184
+
background-color: darkgoldenrod
1185
+
}
1186
+
",
1187
+
"",
1188
+
],
1189
+
]
1190
+
`;
1191
+
1192
+
exports[`"modules" option should invoke the custom getJSON function with getJSON as a function: warnings 1`] = `Array []`;
1193
+
1125
1194
exports[`"modules" option should keep order: errors 1`] = `Array []`;
1126
1195
1127
1196
exports[`"modules" option should keep order: module 1`] = `
@@ -1194,6 +1263,69 @@ Array [
1194
1263
1195
1264
exports[`"modules" option should keep order: warnings 1`] = `Array []`;
1196
1265
1266
+
exports[`"modules" option should output a co-located CSS modules map file with getJSON as true: errors 1`] = `Array []`;
1267
+
1268
+
exports[`"modules" option should output a co-located CSS modules map file with getJSON as true: mapping 1`] = `"{\\"a\\":\\"RT7ktT7mB7tfBR25sJDZ\\",\\"b\\":\\"IZmhTnK9CIeu6ww6Zjbv\\",\\"c\\":\\"PV11nPFlF7mzEgCXkQw4\\"}"`;
1269
+
1270
+
exports[`"modules" option should output a co-located CSS modules map file with getJSON as true: module 1`] = `
1271
+
"// Imports
1272
+
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
1273
+
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
1274
+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
0 commit comments