Skip to content

Commit b178f90

Browse files
Copilotsapphi-red
andauthored
feat(create-vite): set default title in index.html to project name (#20519)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent 03a56c5 commit b178f90

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,15 @@ test('return help usage how to use create-vite with -h alias', () => {
171171
const message = 'Usage: create-vite [OPTION]... [DIRECTORY]'
172172
expect(stdout).toContain(message)
173173
})
174+
175+
test('sets index.html title to project name', () => {
176+
const { stdout } = run([projectName, '--template', 'react'], {
177+
cwd: __dirname,
178+
})
179+
180+
const indexHtmlPath = path.join(genPath, 'index.html')
181+
const indexHtmlContent = fs.readFileSync(indexHtmlPath, 'utf-8')
182+
183+
expect(stdout).toContain(`Scaffolding project in ${genPath}`)
184+
expect(indexHtmlContent).toContain(`<title>${projectName}</title>`)
185+
})

packages/create-vite/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ async function init() {
537537
const targetPath = path.join(root, renameFiles[file] ?? file)
538538
if (content) {
539539
fs.writeFileSync(targetPath, content)
540+
} else if (file === 'index.html') {
541+
const templatePath = path.join(templateDir, file)
542+
const templateContent = fs.readFileSync(templatePath, 'utf-8')
543+
const updatedContent = templateContent.replace(
544+
/<title>.*?<\/title>/,
545+
`<title>${packageName}</title>`,
546+
)
547+
fs.writeFileSync(targetPath, updatedContent)
540548
} else {
541549
copy(path.join(templateDir, file), targetPath)
542550
}

0 commit comments

Comments
 (0)