Skip to content

Commit 7f81290

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 50f1234 commit 7f81290

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
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
)}`;

0 commit comments

Comments
 (0)