Skip to content

Commit fd6e995

Browse files
committed
PR feedback
1 parent 3fde4eb commit fd6e995

File tree

4 files changed

+33
-560
lines changed

4 files changed

+33
-560
lines changed

packages/rollup-plugin/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ export function vanillaExtractPlugin({
164164
const name = extract.name || 'bundle.css';
165165
this.emitFile({
166166
type: 'asset',
167-
fileName: name,
167+
name,
168+
originalFileName: name,
168169
source: bundle.toString(),
169170
});
170171
if (extract.sourcemap) {
172+
const sourcemapName = `${name}.map`;
171173
this.emitFile({
172174
type: 'asset',
173-
fileName: `${name}.map`,
174-
source: bundle.generateMap({ file: extract.name }).toString(),
175+
name: sourcemapName,
176+
originalFileName: sourcemapName,
177+
source: bundle.generateMap({ file: name }).toString(),
175178
});
176179
}
177180
},

packages/rollup-plugin/src/lib.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function generateCssBundle({
2626
for (const id of sortModules(cssFiles)) {
2727
const { importedIdResolutions } = getModuleInfo(id) ?? {};
2828
for (const resolution of importedIdResolutions ?? []) {
29-
if (resolution.meta.css) {
29+
if (resolution.meta.css && !extractedCssIds.has(resolution.id)) {
3030
extractedCssIds.add(resolution.id);
3131
cssBundle.addSource({
3232
filename: resolution.id,
@@ -40,20 +40,23 @@ export function generateCssBundle({
4040
}
4141

4242
/** [id, order] tuple meant for ordering imports */
43-
export type ImportChain = [string, number][];
43+
export type ImportChain = [id: string, order: number][];
4444

4545
/** Trace a file back through its importers, building an ordered list */
4646
export function buildImportChain(
4747
id: string,
4848
{ getModuleInfo, warn }: Pick<PluginContext, 'getModuleInfo' | 'warn'>,
4949
): ImportChain {
50-
let mod: ModuleInfo = getModuleInfo(id)!;
50+
let mod: ModuleInfo | null = getModuleInfo(id)!;
51+
if (!mod) {
52+
return [];
53+
}
5154
/** [id, order] */
5255
const chain: ImportChain = [[id, -1]];
5356
// resolve upwards to root entry
5457
while (!mod.isEntry) {
5558
const { id: currentId, importers } = mod;
56-
const lastImporterId = importers.at(-1)!;
59+
const lastImporterId = importers.at(-1);
5760
if (!lastImporterId) {
5861
break;
5962
}
@@ -65,7 +68,7 @@ export function buildImportChain(
6568
);
6669
break;
6770
}
68-
mod = getModuleInfo(lastImporterId)!;
71+
mod = getModuleInfo(lastImporterId);
6972
if (!mod) {
7073
break;
7174
}

0 commit comments

Comments
 (0)