Skip to content

Commit f26b034

Browse files
committed
chore: merge main
2 parents 3b8bc55 + 572aaca commit f26b034

File tree

6 files changed

+86
-47
lines changed

6 files changed

+86
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.log
88
/.vscode/
99
/docs/.vitepress/cache
10+
/docs/.vitepress/.temp
1011
/packages/vite/LICENSE
1112
dist
1213
dist-ssr

docs/.vitepress/config.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
groupIconVitePlugin,
99
} from 'vitepress-plugin-group-icons'
1010
import llmstxt from 'vitepress-plugin-llms'
11-
import type { PluginOption } from 'vite'
1211
import { markdownItImageSize } from 'markdown-it-image-size'
1312
import packageJson from '../../packages/vite/package.json' with { type: 'json' }
1413
import { buildEnd } from './buildEnd.config'
@@ -95,30 +94,6 @@ export default defineConfig({
9594
'link',
9695
{ rel: 'alternate', type: 'application/rss+xml', href: '/blog.rss' },
9796
],
98-
['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
99-
[
100-
'link',
101-
{
102-
rel: 'preconnect',
103-
href: 'https://fonts.gstatic.com',
104-
crossorigin: 'true',
105-
},
106-
],
107-
[
108-
'link',
109-
{
110-
rel: 'preload',
111-
href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap',
112-
as: 'style',
113-
},
114-
],
115-
[
116-
'link',
117-
{
118-
rel: 'stylesheet',
119-
href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap',
120-
},
121-
],
12297
inlineScript('banner.js'),
12398
['link', { rel: 'me', href: 'https://m.webtoo.ls/@vite' }],
12499
['meta', { property: 'og:type', content: 'website' }],
@@ -468,16 +443,34 @@ export default defineConfig({
468443
level: [2, 3],
469444
},
470445
},
471-
transformPageData(pageData) {
472-
const canonicalUrl = `${ogUrl}/${pageData.relativePath}`
473-
.replace(/\/index\.md$/, '/')
474-
.replace(/\.md$/, '')
475-
pageData.frontmatter.head ??= []
476-
pageData.frontmatter.head.unshift(
477-
['link', { rel: 'canonical', href: canonicalUrl }],
478-
['meta', { property: 'og:title', content: pageData.title }],
479-
)
480-
return pageData
446+
transformHead(ctx) {
447+
const path = ctx.page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '')
448+
449+
if (path !== '404') {
450+
const canonicalUrl = path ? `${ogUrl}/${path}` : ogUrl
451+
ctx.head.push(
452+
['link', { rel: 'canonical', href: canonicalUrl }],
453+
['meta', { property: 'og:title', content: ctx.pageData.title }],
454+
)
455+
}
456+
457+
// For the landing page, move the google font links to the top for better performance
458+
if (path === '') {
459+
const googleFontLinks: HeadConfig[] = []
460+
for (let i = 0; i < ctx.head.length; i++) {
461+
const tag = ctx.head[i]
462+
if (
463+
tag[0] === 'link' &&
464+
(tag[1]?.href?.includes('fonts.googleapis.com') ||
465+
tag[1]?.href?.includes('fonts.gstatic.com'))
466+
) {
467+
ctx.head.splice(i, 1)
468+
googleFontLinks.push(tag)
469+
i--
470+
}
471+
}
472+
ctx.head.unshift(...googleFontLinks)
473+
}
481474
},
482475
markdown: {
483476
// languages used for twoslash and jsdocs in twoslash
@@ -520,7 +513,7 @@ Vite is a new breed of frontend build tooling that significantly improves the fr
520513
- A [build command](https://vite.dev/guide/build.md) that bundles your code with [Rollup](https://rollupjs.org), pre-configured to output highly optimized static assets for production.
521514
522515
In addition, Vite is highly extensible via its [Plugin API](https://vite.dev/guide/api-plugin.md) and [JavaScript API](https://vite.dev/guide/api-javascript.md) with full typing support.`,
523-
}) as PluginOption,
516+
}),
524517
],
525518
optimizeDeps: {
526519
include: [

docs/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ layout: home
99
aside: false
1010
editLink: false
1111
markdownStyles: false
12+
13+
head:
14+
- - link
15+
- rel: preconnect
16+
href: https://fonts.googleapis.com
17+
- - link
18+
- rel: preconnect
19+
href: https://fonts.gstatic.com
20+
crossorigin: ''
21+
- - link
22+
- rel: preload
23+
href: https://fonts.googleapis.com/css2?family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap
24+
as: style
25+
- - link
26+
- rel: stylesheet
27+
href: https://fonts.googleapis.com/css2?family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap
1228
---
1329

1430
<script setup>

packages/create-vite/src/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,7 @@ async function init() {
644644
)
645645
fs.writeFileSync(targetPath, updatedContent)
646646
} else {
647-
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is not experimental in Node 22.3+
648-
fs.cpSync(path.join(templateDir, file), targetPath, {
649-
recursive: true,
650-
mode: fs.constants.COPYFILE_FICLONE,
651-
})
647+
copy(path.join(templateDir, file), targetPath)
652648
}
653649
}
654650

@@ -714,6 +710,15 @@ function formatTargetDir(targetDir: string) {
714710
return targetDir.trim().replace(/\/+$/g, '')
715711
}
716712

713+
function copy(src: string, dest: string) {
714+
const stat = fs.statSync(src)
715+
if (stat.isDirectory()) {
716+
copyDir(src, dest)
717+
} else {
718+
fs.copyFileSync(src, dest)
719+
}
720+
}
721+
717722
function isValidPackageName(projectName: string) {
718723
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(
719724
projectName,
@@ -729,6 +734,15 @@ function toValidPackageName(projectName: string) {
729734
.replace(/[^a-z\d\-~]+/g, '-')
730735
}
731736

737+
function copyDir(srcDir: string, destDir: string) {
738+
fs.mkdirSync(destDir, { recursive: true })
739+
for (const file of fs.readdirSync(srcDir)) {
740+
const srcFile = path.resolve(srcDir, file)
741+
const destFile = path.resolve(destDir, file)
742+
copy(srcFile, destFile)
743+
}
744+
}
745+
732746
function isEmpty(path: string) {
733747
const files = fs.readdirSync(path)
734748
return files.length === 0 || (files.length === 1 && files[0] === '.git')

packages/vite/src/node/plugins/prepareOutDir.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import colors from 'picocolors'
44
import type { Plugin } from '../plugin'
55
import { getResolvedOutDirs, resolveEmptyOutDir } from '../watch'
66
import type { Environment } from '../environment'
7-
import { emptyDir, normalizePath } from '../utils'
7+
import { copyDir, emptyDir, normalizePath } from '../utils'
88
import { withTrailingSlash } from '../../shared/utils'
99

1010
export function prepareOutDirPlugin(): Plugin {
@@ -86,11 +86,7 @@ function prepareOutDir(
8686
),
8787
)
8888
}
89-
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is not experimental in Node 22.3+
90-
fs.cpSync(publicDir, outDir, {
91-
recursive: true,
92-
mode: fs.constants.COPYFILE_FICLONE,
93-
})
89+
copyDir(publicDir, outDir)
9490
}
9591
}
9692
}

packages/vite/src/node/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,25 @@ export function emptyDir(dir: string, skip?: string[]): void {
623623
}
624624
}
625625

626+
// NOTE: we cannot use `fs.cpSync` because of a bug in Node.js (https://github.com/nodejs/node/issues/58768, https://github.com/nodejs/node/issues/59168)
627+
// also note that we should set `dereference: true` when we use `fs.cpSync`
628+
export function copyDir(srcDir: string, destDir: string): void {
629+
fs.mkdirSync(destDir, { recursive: true })
630+
for (const file of fs.readdirSync(srcDir)) {
631+
const srcFile = path.resolve(srcDir, file)
632+
if (srcFile === destDir) {
633+
continue
634+
}
635+
const destFile = path.resolve(destDir, file)
636+
const stat = fs.statSync(srcFile)
637+
if (stat.isDirectory()) {
638+
copyDir(srcFile, destFile)
639+
} else {
640+
fs.copyFileSync(srcFile, destFile)
641+
}
642+
}
643+
}
644+
626645
export const ERR_SYMLINK_IN_RECURSIVE_READDIR =
627646
'ERR_SYMLINK_IN_RECURSIVE_READDIR'
628647
export async function recursiveReaddir(dir: string): Promise<string[]> {

0 commit comments

Comments
 (0)