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 Nov 14, 2024
1 parent f39f6c0 commit 2ff913e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 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 @@ -641,7 +641,19 @@ 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 @@ -799,11 +799,6 @@ async function prepareRolldownOptimizerRun(
extensions: ['.js', '.css'],
conditionNames: ['browser'],
},
// TODO: remove this and enable rolldown's CSS support later
moduleTypes: {
'.css': 'js',
...rollupOptions.moduleTypes,
},
})
if (canceled) {
await bundle.close()
Expand Down Expand Up @@ -1083,11 +1078,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
3 changes: 1 addition & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,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`
// NOTE: add `export {}` otherwise rolldown treats the module as CJS (https://github.com/rolldown/rolldown/issues/2394)
code = 'export {}'
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 @@ -232,7 +232,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 2ff913e

Please sign in to comment.