Skip to content

Commit 513b194

Browse files
committed
fixup!
1 parent 85d907d commit 513b194

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

npm-shrinkwrap.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generators/web/utils/css.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { bundleAsync } from 'lightningcss-wasm';
88
const fileCache = new Map();
99

1010
/**
11-
* Rolldown plugin to support `.module.css` files with CSS Modules semantics.
11+
* Rolldown plugin to support `.css` files with CSS Modules semantics.
1212
*
1313
* This plugin performs the following:
14-
* 1. Intercepts `.module.css` files during the build
14+
* 1. Intercepts `.css` files during the build
1515
* 2. Processes them with Lightning CSS (including CSS Module transformation)
1616
* 3. Collects the resulting CSS to emit as a single `styles.css` file
1717
* 4. Exports the transformed class names back to the JS file
1818
*
19-
* TODO(@avivkeller): Once Rolldown natively supports CSS Modules, this plugin can be removed.
19+
* @returns {import('rolldown').Plugin}
2020
*/
2121
export default () => {
2222
const cssChunks = new Set();
@@ -26,15 +26,15 @@ export default () => {
2626

2727
// Hook into the module loading phase of Rolldown
2828
load: {
29-
// Match only files ending with `.module.css`
29+
// Match only files ending with `.css`
3030
filter: {
3131
id: {
32-
include: /\.module\.css$/,
32+
include: /\.css$/,
3333
},
3434
},
3535

3636
/**
37-
* Load handler to process matched `.module.css` files
37+
* Load handler to process matched `.css` files
3838
*
3939
* @param {string} id - Absolute file path to the CSS file
4040
*/
@@ -59,7 +59,13 @@ export default () => {
5959
const { code, exports } = await bundleAsync({
6060
filename: id,
6161
code: Buffer.from(source),
62-
cssModules: true,
62+
cssModules: id.endsWith('module.css'),
63+
resolver: {
64+
/**
65+
*
66+
*/
67+
resolve: (...args) => this.resolve(...args).then(r => r.id),
68+
},
6369
});
6470

6571
const css = code.toString();
@@ -70,7 +76,7 @@ export default () => {
7076
// Map exported class names to their scoped identifiers
7177
// e.g., { button: '_button_abc123' }
7278
const mappedExports = Object.fromEntries(
73-
Object.entries(exports).map(([key, value]) => [key, value.name])
79+
Object.entries(exports ?? {}).map(([key, value]) => [key, value.name])
7480
);
7581

7682
// Cache result

0 commit comments

Comments
 (0)