Skip to content

Commit

Permalink
wip: use builtin css handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Sep 26, 2024
1 parent 8be28c1 commit 1f97ea1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
14 changes: 13 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,19 @@ export async function buildEnvironment(
// TODO: remove this and enable rolldown's CSS support later
moduleTypes: {
...options.rollupOptions.moduleTypes,
'.css': 'js',
// https://github.com/rolldown/rolldown/blob/4020de442a8ab0f7973794ead3b8aa04e316d558/crates/rolldown/src/module_loader/module_task.rs#L120
// @ts-expect-error css
'.sass': 'css',
// @ts-expect-error css
'.scss': 'css',
// @ts-expect-error css
'.sss': 'css',
// @ts-expect-error css
'.styl': 'css',
// @ts-expect-error css
'.stylus': 'css',
// @ts-expect-error css
'.less': 'css',
},
}

Expand Down
10 changes: 0 additions & 10 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,6 @@ async function prepareRolldownOptimizerRun(
conditionNames: ['browser'],
},
...rollupOptions,
// TODO: remove this and enable rolldown's CSS support later
moduleTypes: {
'.css': 'js',
...rollupOptions.moduleTypes,
},
})
if (canceled) {
await bundle.close()
Expand Down Expand Up @@ -1067,11 +1062,6 @@ export async function extractExportsData(
...remainingRollupOptions,
plugins,
input: [filePath],
// TODO: remove this and enable rolldown's CSS support later
moduleTypes: {
'.css': 'js',
...remainingRollupOptions.moduleTypes,
},
})
const result = await build.generate({
...rollupOptions.output,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
code = `export default ${JSON.stringify(content)}`
} else {
// empty module when it's not a CSS module nor `?inline`
code = ''
code = css
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
}
},

async transform(source, importer) {
async transform(source, importer, opts) {
if (opts?.moduleType === 'css') return
if (isInNodeModules(importer) && !dynamicImportPrefixRE.test(source)) {
return
}
Expand Down
5 changes: 0 additions & 5 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ async function bundleWorkerEntry(
onwarn(warning, warn) {
onRollupWarning(warning, warn, workerEnvironment)
},
// TODO: remove this and enable rolldown's CSS support later
moduleTypes: {
'.css': 'js',
...rollupOptions.moduleTypes,
},
// preserveEntrySignatures: false,
})
let chunk: OutputChunk
Expand Down

0 comments on commit 1f97ea1

Please sign in to comment.