Skip to content

Commit 76666f5

Browse files
committed
wip: use builtin css handling
1 parent 7e142c3 commit 76666f5

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
@@ -651,7 +651,19 @@ async function buildEnvironment(
651651
// TODO: remove this and enable rolldown's CSS support later
652652
moduleTypes: {
653653
...options.rollupOptions.moduleTypes,
654-
'.css': 'js',
654+
// https://github.com/rolldown/rolldown/blob/4020de442a8ab0f7973794ead3b8aa04e316d558/crates/rolldown/src/module_loader/module_task.rs#L120
655+
// @ts-expect-error css
656+
'.sass': 'css',
657+
// @ts-expect-error css
658+
'.scss': 'css',
659+
// @ts-expect-error css
660+
'.sss': 'css',
661+
// @ts-expect-error css
662+
'.styl': 'css',
663+
// @ts-expect-error css
664+
'.stylus': 'css',
665+
// @ts-expect-error css
666+
'.less': 'css',
655667
},
656668
}
657669

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
@@ -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)