Skip to content

Commit 96389ce

Browse files
committed
allow plugin to work in rolldown
rolldown does not expose importedIdResolutions similar to rollup and so we need to move the emit to the render phase
1 parent 9446b1a commit 96389ce

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

.changeset/light-guests-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/rollup-plugin': patch
3+
---
4+
5+
allow plugin to work in rolldown

packages/rollup-plugin/src/index.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,21 @@ export function vanillaExtractPlugin({
116116
},
117117
};
118118
},
119-
120-
// Emit .css assets
121-
moduleParsed(moduleInfo) {
122-
moduleInfo.importedIdResolutions.forEach((resolution) => {
123-
if (resolution.meta.css && !extract) {
124-
resolution.meta.assetId = this.emitFile({
125-
type: 'asset',
126-
name: resolution.id,
127-
source: resolution.meta.css,
128-
});
129-
}
130-
});
131-
},
132-
133-
// Replace .css import paths with relative paths to emitted css files
119+
// Emit .css assets and replace .css import paths with relative paths to emitted css files
134120
renderChunk(code, chunkInfo) {
135121
const chunkPath = dirname(chunkInfo.fileName);
136122
const output = chunkInfo.imports.reduce((codeResult, importPath) => {
137123
const moduleInfo = this.getModuleInfo(importPath);
138-
if (!moduleInfo?.meta.assetId) {
124+
if (!moduleInfo?.meta.css || extract) {
139125
return codeResult;
140126
}
141127

142-
const assetPath = this.getFileName(moduleInfo?.meta.assetId);
128+
const assetId = this.emitFile({
129+
type: 'asset',
130+
name: moduleInfo.id,
131+
source: moduleInfo.meta.css,
132+
});
133+
const assetPath = this.getFileName(assetId);
143134
const relativeAssetPath = `./${normalize(
144135
relative(chunkPath, assetPath),
145136
)}`;

packages/rollup-plugin/src/lib.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export function generateCssBundle(
2222

2323
// 2. build bundle from import order
2424
for (const id of sortModules(cssFiles)) {
25-
const { importedIdResolutions } = plugin.getModuleInfo(id) ?? {};
26-
for (const resolution of importedIdResolutions ?? []) {
27-
if (resolution.meta.css && !extractedCssIds.has(resolution.id)) {
25+
const { importedIds } = plugin.getModuleInfo(id) ?? {};
26+
for (const importedId of importedIds ?? []) {
27+
const resolution = plugin.getModuleInfo(importedId);
28+
if (resolution?.meta.css && !extractedCssIds.has(resolution.id)) {
2829
extractedCssIds.add(resolution.id);
2930
cssBundle.addSource({
3031
filename: resolution.id,

0 commit comments

Comments
 (0)