Skip to content

Commit b3227d5

Browse files
authored
feat(create-vite): scaffold with rolldown-vite (#20739)
1 parent 52469c3 commit b3227d5

File tree

3 files changed

+87
-8
lines changed

3 files changed

+87
-8
lines changed

docs/guide/rolldown.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ If you use a Vitepress or a meta framework that has Vite as peer dependency, you
8585

8686
After adding these overrides, reinstall your dependencies and start your development server or build your project as usual. No further configuration changes are required.
8787

88+
If you are starting a new project, you can use `create-vite` as normal for rolldown-vite, too. The latest version will ask you whether to use `rolldown-vite` or not.
89+
8890
## Known Limitations
8991

9092
While Rolldown aims to be a drop-in replacement for Rollup, there are features that are still being implemented and minor intentional behavior differences. For a comprehensive list, please refer to [this GitHub PR](https://github.com/vitejs/rolldown-vite/pull/84#issue-2903144667) which is regularly updated.

packages/create-vite/__tests__/cli.spec.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ test('asks to overwrite non-empty current directory', () => {
110110
})
111111

112112
test('successfully scaffolds a project based on vue starter template', () => {
113-
const { stdout } = run([projectName, '--interactive', '--template', 'vue'], {
114-
cwd: __dirname,
115-
})
113+
const { stdout } = run(
114+
[projectName, '--interactive', '--template', 'vue', '--no-rolldown'],
115+
{
116+
cwd: __dirname,
117+
},
118+
)
116119
const generatedFiles = fs.readdirSync(genPath).sort()
117120

118121
// Assertions
@@ -122,7 +125,13 @@ test('successfully scaffolds a project based on vue starter template', () => {
122125

123126
test('successfully scaffolds a project with subfolder based on react starter template', () => {
124127
const { stdout } = run(
125-
[`subfolder/${projectName}`, '--interactive', '--template', 'react'],
128+
[
129+
`subfolder/${projectName}`,
130+
'--interactive',
131+
'--template',
132+
'react',
133+
'--no-rolldown',
134+
],
126135
{
127136
cwd: __dirname,
128137
},
@@ -134,10 +143,32 @@ test('successfully scaffolds a project with subfolder based on react starter tem
134143
expect(templateFilesReact).toEqual(generatedFiles)
135144
})
136145

146+
test('successfully scaffolds a project with subfolder based on react starter template with rolldown flag', () => {
147+
const { stdout } = run(
148+
[`subfolder/${projectName}`, '--template', 'react', '--rolldown'],
149+
{
150+
cwd: __dirname,
151+
},
152+
)
153+
const generatedFiles = fs.readdirSync(genPathWithSubfolder).sort()
154+
155+
// Assertions
156+
expect(stdout).toContain(`Scaffolding project in ${genPathWithSubfolder}`)
157+
expect(templateFilesReact).toEqual(generatedFiles)
158+
const generatedPackageJson = fs.readFileSync(
159+
path.join(genPathWithSubfolder, 'package.json'),
160+
'utf-8',
161+
)
162+
expect(generatedPackageJson).toContain('rolldown-vite')
163+
})
164+
137165
test('works with the -t alias', () => {
138-
const { stdout } = run([projectName, '--interactive', '-t', 'vue'], {
139-
cwd: __dirname,
140-
})
166+
const { stdout } = run(
167+
[projectName, '--interactive', '-t', 'vue', '--no-rolldown'],
168+
{
169+
cwd: __dirname,
170+
},
171+
)
141172
const generatedFiles = fs.readdirSync(genPath).sort()
142173

143174
// Assertions

packages/create-vite/src/index.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const argv = mri<{
2323
template?: string
2424
help?: boolean
2525
overwrite?: boolean
26+
rolldown?: boolean
2627
interactive?: boolean
2728
}>(process.argv.slice(2), {
2829
alias: { h: 'help', t: 'template' },
29-
boolean: ['help', 'overwrite', 'interactive'],
30+
boolean: ['help', 'overwrite', 'rolldown', 'interactive'],
3031
string: ['template'],
3132
})
3233
const cwd = process.cwd()
@@ -40,6 +41,7 @@ When running in TTY, the CLI will start in interactive mode.
4041
4142
Options:
4243
-t, --template NAME use a specific template
44+
--rolldown / --no-rolldown use / do not use rolldown-vite (Experimental)
4345
--interactive / --no-interactive force interactive / non-interactive mode
4446
4547
Available templates:
@@ -348,6 +350,7 @@ async function init() {
348350
: undefined
349351
const argTemplate = argv.template
350352
const argOverwrite = argv.overwrite
353+
const argRolldown = argv.rolldown
351354
const argInteractive = argv.interactive
352355

353356
const help = argv.help
@@ -525,6 +528,28 @@ async function init() {
525528
process.exit(status ?? 0)
526529
}
527530

531+
let useRolldownVite = argRolldown
532+
if (useRolldownVite === undefined) {
533+
if (interactive) {
534+
const rolldownViteValue = await prompts.select({
535+
message: 'Use rolldown-vite (Experimental)?:',
536+
options: [
537+
{
538+
label: 'Yes',
539+
value: true,
540+
hint: 'The future default Vite, which is powered by Rolldown',
541+
},
542+
{ label: 'No', value: false },
543+
],
544+
initialValue: false,
545+
})
546+
if (prompts.isCancel(rolldownViteValue)) return cancel()
547+
useRolldownVite = rolldownViteValue
548+
} else {
549+
useRolldownVite = false
550+
}
551+
}
552+
528553
prompts.log.step(`Scaffolding project in ${root}...`)
529554

530555
const templateDir = path.resolve(
@@ -561,6 +586,27 @@ async function init() {
561586

562587
pkg.name = packageName
563588

589+
if (useRolldownVite) {
590+
// renovate: datasource=npm depName=rolldown-vite
591+
const rolldownViteVersion = '7.1.12'
592+
const pkgVersion = `npm:rolldown-vite@${rolldownViteVersion}`
593+
pkg.devDependencies.vite = pkgVersion
594+
switch (pkgManager) {
595+
case 'pnpm':
596+
pkg.pnpm ??= {}
597+
pkg.pnpm.overrides ??= {}
598+
pkg.pnpm.overrides.vite = pkgVersion
599+
break
600+
case 'yarn':
601+
pkg.resolutions ??= {}
602+
pkg.resolutions.vite = pkgVersion
603+
break
604+
default:
605+
pkg.overrides ??= {}
606+
pkg.overrides.vite = pkgVersion
607+
}
608+
}
609+
564610
write('package.json', JSON.stringify(pkg, null, 2) + '\n')
565611

566612
if (isReactSwc) {

0 commit comments

Comments
 (0)