From ce2a95fcd39d3db43b846a7ad98e00d0dbaf6726 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 2 Aug 2023 12:56:55 -0700 Subject: [PATCH 1/7] Add Bun to docs --- docs/guide/index.md | 7 +++++++ docs/guide/troubleshooting.md | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index c45e1711d69dbe..c82973a840dedb 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -59,6 +59,10 @@ $ yarn create vite $ pnpm create vite ``` +```bash [Bun] +$ bunx create-vite +``` + ::: Then follow the prompts! @@ -77,6 +81,9 @@ yarn create vite my-vue-app --template vue # pnpm pnpm create vite my-vue-app --template vue + +# bun +bunx create-vite my-vue-app --template vue ``` See [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite) for more details on each supported template: `vanilla`, `vanilla-ts`, `vue`, `vue-ts`, `react`, `react-ts`, `react-swc`, `react-swc-ts`, `preact`, `preact-ts`, `lit`, `lit-ts`, `svelte`, `svelte-ts`, `solid`, `solid-ts`, `qwik`, `qwik-ts`. diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index e5bfd3869fb647..82f7d31092c216 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -12,7 +12,7 @@ The path to your project folder may include `&`, which doesn't work with `npm` o You will need to either: -- Switch to another package manager (e.g. `pnpm`, `yarn`) +- Switch to another package manager (e.g. `pnpm`, `yarn`, `bun`) - Remove `&` from the path to your project ## Config @@ -142,7 +142,7 @@ You will need to access the file with `http` protocol. The easiest way to achiev ### Outdated pre-bundled deps when linking to a local package -The hash key used to invalidate optimized dependencies depend on the package lock contents, the patches applied to dependencies, and the options in the Vite config file that affects the bundling of node modules. This means that Vite will detect when a dependency is overridden using a feature as [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides), and re-bundle your dependencies on the next server start. Vite won't invalidate the dependencies when you use a feature like [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link). In case you link or unlink a dependency, you'll need to force re-optimization on the next server start by using `vite --force`. We recommend using overrides instead, which are supported now by every package manager (see also [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides) and [yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions)). +The hash key used to invalidate optimized dependencies depends on the `package-lock.json` contents, the patches applied to dependencies, and the options in the Vite config file that affects the bundling of `node_modules`. This means Vite will detect when a dependency is overridden using a feature like [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) and re-bundle your dependencies on the next server start. Vite won't invalidate the dependencies when you use a feature like [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link). In case you link or unlink a dependency, you'll need to force re-optimization on the next server start by using `vite --force`. We recommend using overrides instead, which are supported now by pnpm (see [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides)) and Yarn (see [yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions)). ## Performance bottlenecks From ecedd57b0a0a0d2ffe87d55d3331ea52d0fa1068 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 3 Aug 2023 12:14:21 -0700 Subject: [PATCH 2/7] Rewrite scripts to use Bun runtime --- packages/create-vite/src/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 20212c337580dd..c001abd818113c 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -428,6 +428,24 @@ async function init() { pkg.name = packageName || getProjectName() + console.log('pkgManager', pkgManager) + if (pkgManager === 'bun') { + console.log(pkg) + // run `vite` CLI with Bun runtime + // the --bun flag is required to override the node shebang + // after Bun 1.0 this will no longer be necessary + if (pkg.scripts) { + pkg.scripts = { + ...pkg.scripts, + dev: pkg.scripts.dev?.replace('vite', 'bunx --bun vite'), + build: pkg.scripts.build?.replace( + 'vite build', + 'bunx --bun vite build', + ), + } + } + } + write('package.json', JSON.stringify(pkg, null, 2) + '\n') if (isReactSwc) { From 8cd27291b0802976c45fbbf95c5dd6592ee9215b Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 3 Aug 2023 12:41:30 -0700 Subject: [PATCH 3/7] Remove logging --- packages/create-vite/src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index c001abd818113c..d881d0741bdf1c 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -428,9 +428,7 @@ async function init() { pkg.name = packageName || getProjectName() - console.log('pkgManager', pkgManager) if (pkgManager === 'bun') { - console.log(pkg) // run `vite` CLI with Bun runtime // the --bun flag is required to override the node shebang // after Bun 1.0 this will no longer be necessary From d65db27be63a0b308919f52badc57899876b70eb Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Mon, 7 Aug 2023 13:05:36 -0700 Subject: [PATCH 4/7] Remove changes to troubleshooting --- docs/guide/troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 82f7d31092c216..ee3eca23090711 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -142,7 +142,7 @@ You will need to access the file with `http` protocol. The easiest way to achiev ### Outdated pre-bundled deps when linking to a local package -The hash key used to invalidate optimized dependencies depends on the `package-lock.json` contents, the patches applied to dependencies, and the options in the Vite config file that affects the bundling of `node_modules`. This means Vite will detect when a dependency is overridden using a feature like [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) and re-bundle your dependencies on the next server start. Vite won't invalidate the dependencies when you use a feature like [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link). In case you link or unlink a dependency, you'll need to force re-optimization on the next server start by using `vite --force`. We recommend using overrides instead, which are supported now by pnpm (see [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides)) and Yarn (see [yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions)). +The hash key used to invalidate optimized dependencies depend on the package lock contents, the patches applied to dependencies, and the options in the Vite config file that affects the bundling of node modules. This means that Vite will detect when a dependency is overridden using a feature as [npm overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides), and re-bundle your dependencies on the next server start. Vite won't invalidate the dependencies when you use a feature like [npm link](https://docs.npmjs.com/cli/v9/commands/npm-link). In case you link or unlink a dependency, you'll need to force re-optimization on the next server start by using `vite --force`. We recommend using overrides instead, which are supported now by every package manager (see also [pnpm overrides](https://pnpm.io/package_json#pnpmoverrides) and [yarn resolutions](https://yarnpkg.com/configuration/manifest/#resolutions)). ## Performance bottlenecks From 84dbe30777a82b2904aac981a914b7f9b12e03a5 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Mon, 7 Aug 2023 13:09:41 -0700 Subject: [PATCH 5/7] Use mutations --- packages/create-vite/src/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index d881d0741bdf1c..675e6f535889c7 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -433,14 +433,11 @@ async function init() { // the --bun flag is required to override the node shebang // after Bun 1.0 this will no longer be necessary if (pkg.scripts) { - pkg.scripts = { - ...pkg.scripts, - dev: pkg.scripts.dev?.replace('vite', 'bunx --bun vite'), - build: pkg.scripts.build?.replace( - 'vite build', - 'bunx --bun vite build', - ), - } + pkg.scripts.dev = pkg.scripts.dev?.replace('vite', 'bunx --bun vite') + pkg.scripts.build = pkg.scripts.build?.replace( + 'vite build', + 'bunx --bun vite build', + ) } } From a025419ce2e254037a7cff8d7148d5e38df2ccd7 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 16 Aug 2023 18:38:56 -0700 Subject: [PATCH 6/7] Undo changes to scripts --- packages/create-vite/src/index.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 675e6f535889c7..20212c337580dd 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -428,19 +428,6 @@ async function init() { pkg.name = packageName || getProjectName() - if (pkgManager === 'bun') { - // run `vite` CLI with Bun runtime - // the --bun flag is required to override the node shebang - // after Bun 1.0 this will no longer be necessary - if (pkg.scripts) { - pkg.scripts.dev = pkg.scripts.dev?.replace('vite', 'bunx --bun vite') - pkg.scripts.build = pkg.scripts.build?.replace( - 'vite build', - 'bunx --bun vite build', - ) - } - } - write('package.json', JSON.stringify(pkg, null, 2) + '\n') if (isReactSwc) { From f03c23c01fc0505c40111d790f38cc23da40a0f7 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 30 Aug 2023 18:15:44 -0700 Subject: [PATCH 7/7] Update readme --- docs/guide/troubleshooting.md | 2 +- packages/create-vite/README.md | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index ee3eca23090711..e5bfd3869fb647 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -12,7 +12,7 @@ The path to your project folder may include `&`, which doesn't work with `npm` o You will need to either: -- Switch to another package manager (e.g. `pnpm`, `yarn`, `bun`) +- Switch to another package manager (e.g. `pnpm`, `yarn`) - Remove `&` from the path to your project ## Config diff --git a/packages/create-vite/README.md b/packages/create-vite/README.md index ea05ce4009beaf..8a4f5abf71277c 100644 --- a/packages/create-vite/README.md +++ b/packages/create-vite/README.md @@ -23,6 +23,12 @@ With PNPM: $ pnpm create vite ``` +With Bun: + +```bash +$ bunx create-vite +``` + Then follow the prompts! You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + Vue project, run: @@ -39,6 +45,9 @@ yarn create vite my-vue-app --template vue # pnpm pnpm create vite my-vue-app --template vue + +# Bun +bunx create-vite my-vue-app --template vue ``` Currently supported template presets include: