Skip to content

Commit 1f97ea1

Browse files
committed
wip: use builtin css handling
1 parent 8be28c1 commit 1f97ea1

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

packages/vite/src/node/build.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,19 @@ export async function buildEnvironment(
649649
// TODO: remove this and enable rolldown's CSS support later
650650
moduleTypes: {
651651
...options.rollupOptions.moduleTypes,
652-
'.css': 'js',
652+
// https://github.com/rolldown/rolldown/blob/4020de442a8ab0f7973794ead3b8aa04e316d558/crates/rolldown/src/module_loader/module_task.rs#L120
653+
// @ts-expect-error css
654+
'.sass': 'css',
655+
// @ts-expect-error css
656+
'.scss': 'css',
657+
// @ts-expect-error css
658+
'.sss': 'css',
659+
// @ts-expect-error css
660+
'.styl': 'css',
661+
// @ts-expect-error css
662+
'.stylus': 'css',
663+
// @ts-expect-error css
664+
'.less': 'css',
653665
},
654666
}
655667

packages/vite/src/node/optimizer/index.ts

-10
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,6 @@ async function prepareRolldownOptimizerRun(
781781
conditionNames: ['browser'],
782782
},
783783
...rollupOptions,
784-
// TODO: remove this and enable rolldown's CSS support later
785-
moduleTypes: {
786-
'.css': 'js',
787-
...rollupOptions.moduleTypes,
788-
},
789784
})
790785
if (canceled) {
791786
await bundle.close()
@@ -1067,11 +1062,6 @@ export async function extractExportsData(
10671062
...remainingRollupOptions,
10681063
plugins,
10691064
input: [filePath],
1070-
// TODO: remove this and enable rolldown's CSS support later
1071-
moduleTypes: {
1072-
'.css': 'js',
1073-
...remainingRollupOptions.moduleTypes,
1074-
},
10751065
})
10761066
const result = await build.generate({
10771067
...rollupOptions.output,

packages/vite/src/node/plugins/css.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
577577
code = `export default ${JSON.stringify(content)}`
578578
} else {
579579
// empty module when it's not a CSS module nor `?inline`
580-
code = ''
580+
code = css
581581
}
582582

583583
return {

packages/vite/src/node/plugins/importAnalysisBuild.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
221221
}
222222
},
223223

224-
async transform(source, importer) {
224+
async transform(source, importer, opts) {
225+
if (opts?.moduleType === 'css') return
225226
if (isInNodeModules(importer) && !dynamicImportPrefixRE.test(source)) {
226227
return
227228
}

packages/vite/src/node/plugins/worker.ts

-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ async function bundleWorkerEntry(
8585
onwarn(warning, warn) {
8686
onRollupWarning(warning, warn, workerEnvironment)
8787
},
88-
// TODO: remove this and enable rolldown's CSS support later
89-
moduleTypes: {
90-
'.css': 'js',
91-
...rollupOptions.moduleTypes,
92-
},
9388
// preserveEntrySignatures: false,
9489
})
9590
let chunk: OutputChunk

0 commit comments

Comments
 (0)