Skip to content

Commit a77fa37

Browse files
committed
wip: use builtin css handling
1 parent 665f619 commit a77fa37

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

packages/vite/src/node/build.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,19 @@ async function buildEnvironment(
641641
// TODO: remove this and enable rolldown's CSS support later
642642
moduleTypes: {
643643
...options.rollupOptions.moduleTypes,
644-
'.css': 'js',
644+
// https://github.com/rolldown/rolldown/blob/4020de442a8ab0f7973794ead3b8aa04e316d558/crates/rolldown/src/module_loader/module_task.rs#L120
645+
// @ts-expect-error css
646+
'.sass': 'css',
647+
// @ts-expect-error css
648+
'.scss': 'css',
649+
// @ts-expect-error css
650+
'.sss': 'css',
651+
// @ts-expect-error css
652+
'.styl': 'css',
653+
// @ts-expect-error css
654+
'.stylus': 'css',
655+
// @ts-expect-error css
656+
'.less': 'css',
645657
},
646658
}
647659

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

-10
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,6 @@ async function prepareRolldownOptimizerRun(
799799
extensions: ['.js', '.css'],
800800
conditionNames: ['browser'],
801801
},
802-
// TODO: remove this and enable rolldown's CSS support later
803-
moduleTypes: {
804-
'.css': 'js',
805-
...rollupOptions.moduleTypes,
806-
},
807802
})
808803
if (canceled) {
809804
await bundle.close()
@@ -1083,11 +1078,6 @@ export async function extractExportsData(
10831078
...remainingRollupOptions,
10841079
plugins,
10851080
input: [filePath],
1086-
// TODO: remove this and enable rolldown's CSS support later
1087-
moduleTypes: {
1088-
'.css': 'js',
1089-
...remainingRollupOptions.moduleTypes,
1090-
},
10911081
})
10921082
const result = await build.generate({
10931083
...rollupOptions.output,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
622622
code = `export default ${JSON.stringify(content)}`
623623
} else {
624624
// empty module when it's not a CSS module nor `?inline`
625-
// NOTE: add `export {}` otherwise rolldown treats the module as CJS (https://github.com/rolldown/rolldown/issues/2394)
626-
code = 'export {}'
625+
code = css
627626
}
628627

629628
return {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
232232
}
233233
},
234234

235-
async transform(source, importer) {
235+
async transform(source, importer, opts) {
236+
if (opts?.moduleType === 'css') return
236237
if (isInNodeModules(importer) && !dynamicImportPrefixRE.test(source)) {
237238
return
238239
}

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)