Skip to content

Commit 1b9dd7b

Browse files
committed
wip: use builtin css handling
1 parent 5d478e0 commit 1b9dd7b

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
@@ -644,7 +644,19 @@ async function buildEnvironment(
644644
// TODO: remove this and enable rolldown's CSS support later
645645
moduleTypes: {
646646
...options.rollupOptions.moduleTypes,
647-
'.css': 'js',
647+
// https://github.com/rolldown/rolldown/blob/4020de442a8ab0f7973794ead3b8aa04e316d558/crates/rolldown/src/module_loader/module_task.rs#L120
648+
// @ts-expect-error css
649+
'.sass': 'css',
650+
// @ts-expect-error css
651+
'.scss': 'css',
652+
// @ts-expect-error css
653+
'.sss': 'css',
654+
// @ts-expect-error css
655+
'.styl': 'css',
656+
// @ts-expect-error css
657+
'.stylus': 'css',
658+
// @ts-expect-error css
659+
'.less': 'css',
648660
},
649661
}
650662

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

-10
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,6 @@ async function prepareRolldownOptimizerRun(
794794
extensions: ['.js', '.css'],
795795
conditionNames: ['browser'],
796796
},
797-
// TODO: remove this and enable rolldown's CSS support later
798-
moduleTypes: {
799-
'.css': 'js',
800-
...rollupOptions.moduleTypes,
801-
},
802797
})
803798
if (canceled) {
804799
await bundle.close()
@@ -1078,11 +1073,6 @@ export async function extractExportsData(
10781073
...remainingRollupOptions,
10791074
plugins,
10801075
input: [filePath],
1081-
// TODO: remove this and enable rolldown's CSS support later
1082-
moduleTypes: {
1083-
'.css': 'js',
1084-
...remainingRollupOptions.moduleTypes,
1085-
},
10861076
})
10871077
const result = await build.generate({
10881078
...rollupOptions.output,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
611611
code = `export default ${JSON.stringify(content)}`
612612
} else {
613613
// empty module when it's not a CSS module nor `?inline`
614-
// NOTE: add `export {}` otherwise rolldown treats the module as CJS (https://github.com/rolldown/rolldown/issues/2394)
615-
code = 'export {}'
614+
code = css
616615
}
617616

618617
return {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
235235
}
236236
},
237237

238-
async transform(source, importer) {
238+
async transform(source, importer, opts) {
239+
if (opts?.moduleType === 'css') return
239240
if (isInNodeModules(importer) && !dynamicImportPrefixRE.test(source)) {
240241
return
241242
}

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)