Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: use builtin css handling #59

Draft
wants to merge 1 commit into
base: rolldown-v6
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,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 @@ -235,7 +235,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
Loading