Skip to content

Commit

Permalink
fix(optimizer): merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
swandir committed Feb 10, 2022
2 parents 19f7d9a + e38be3e commit 92f50a9
Show file tree
Hide file tree
Showing 106 changed files with 1,893 additions and 1,299 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Expand Up @@ -66,7 +66,7 @@ body:
required: true
- label: Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
required: true
- label: Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- label: Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
required: true
- label: Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
required: true
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/sponsors.css
Expand Up @@ -5,7 +5,7 @@

.sponsors a {
color: #999;
margin: 1em;
margin: 1em 2em;
display: block;
}

Expand Down Expand Up @@ -45,7 +45,7 @@
.gold-sponsors {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
justify-content: center;
align-items: center;
}

Expand Down
12 changes: 6 additions & 6 deletions docs/.vitepress/theme/sponsors.json
Expand Up @@ -6,6 +6,12 @@
"src": "/stackblitz.svg",
"tier": "platinum"
},
{
"id": "cypress",
"name": "Cypress.io",
"href": "https://cypress.io",
"src": "/cypress.svg"
},
{
"id": "tailwind",
"name": "Tailwind Labs",
Expand Down Expand Up @@ -35,11 +41,5 @@
"name": "divriots",
"href": "https://divriots.com/",
"src": "/divriots.png"
},
{
"id": "finclip",
"name": "FinClip",
"href": "https://finclip.com/?from=vite",
"src": "/finclip.png"
}
]
52 changes: 30 additions & 22 deletions docs/guide/api-plugin.md
Expand Up @@ -36,9 +36,7 @@ If your plugin is only going to work for a particular framework, its name should
- `vite-plugin-react-` prefix for React Plugins
- `vite-plugin-svelte-` prefix for Svelte Plugins

Vite convention for virtual modules is to prefix the user-facing path with `virtual:`. If possible the plugin name should be used as a namespace to avoid collisions with other plugins in the ecosystem. For example, a `vite-plugin-posts` could ask users to import a `virtual:posts` or `virtual:posts/helpers` virtual modules to get build time information. Internally, plugins that use virtual modules should prefix the module ID with `\0` while resolving the id, a convention from the rollup ecosystem. This prevents other plugins from trying to process the id (like node resolution), and core features like sourcemaps can use this info to differentiate between virtual modules and regular files. `\0` is not a permitted char in import URLs so we have to replace them during import analysis. A `\0{id}` virtual id ends up encoded as `/@id/__x00__{id}` during dev in the browser. The id will be decoded back before entering the plugins pipeline, so this is not seen by plugins hooks code.

Note that modules directly derived from a real file, as in the case of a script module in a Single File Component (like a .vue or .svelte SFC) don't need to follow this convention. SFCs generally generate a set of submodules when processed but the code in these can be mapped back to the filesystem. Using `\0` for these submodules would prevent sourcemaps from working correctly.
See also [Virtual Modules Convention](#virtual-modules-convention).

## Plugins config

Expand Down Expand Up @@ -84,8 +82,35 @@ export default defineConfig({
It is common convention to author a Vite/Rollup plugin as a factory function that returns the actual plugin object. The function can accept options which allows users to customize the behavior of the plugin.
:::

### Transforming Custom File Types

```js
const fileRegex = /\.(my-file-ext)$/

export default function myPlugin() {
return {
name: 'transform-file',

transform(src, id) {
if (fileRegex.test(id)) {
return {
code: compileFileToJS(src),
map: null // provide source map if available
}
}
}
}
}
```

### Importing a Virtual File

See the example in the [next section](#virtual-modules-convention).

## Virtual Modules Convention

Virtual modules are a useful scheme that allows you to pass build time information to the source files using normal ESM import syntax.

```js
export default function myPlugin() {
const virtualModuleId = '@my-virtual-module'
Expand Down Expand Up @@ -115,26 +140,9 @@ import { msg } from '@my-virtual-module'
console.log(msg)
```

### Transforming Custom File Types

```js
const fileRegex = /\.(my-file-ext)$/

export default function myPlugin() {
return {
name: 'transform-file',
Virtual modules in Vite (and Rollup) are prefixed with `virtual:` for the user-facing path by convention. If possible the plugin name should be used as a namespace to avoid collisions with other plugins in the ecosystem. For example, a `vite-plugin-posts` could ask users to import a `virtual:posts` or `virtual:posts/helpers` virtual modules to get build time information. Internally, plugins that use virtual modules should prefix the module ID with `\0` while resolving the id, a convention from the rollup ecosystem. This prevents other plugins from trying to process the id (like node resolution), and core features like sourcemaps can use this info to differentiate between virtual modules and regular files. `\0` is not a permitted char in import URLs so we have to replace them during import analysis. A `\0{id}` virtual id ends up encoded as `/@id/__x00__{id}` during dev in the browser. The id will be decoded back before entering the plugins pipeline, so this is not seen by plugins hooks code.

transform(src, id) {
if (fileRegex.test(id)) {
return {
code: compileFileToJS(src),
map: null // provide source map if available
}
}
}
}
}
```
Note that modules directly derived from a real file, as in the case of a script module in a Single File Component (like a .vue or .svelte SFC) don't need to follow this convention. SFCs generally generate a set of submodules when processed but the code in these can be mapped back to the filesystem. Using `\0` for these submodules would prevent sourcemaps from working correctly.

## Universal Hooks

Expand Down
29 changes: 22 additions & 7 deletions docs/guide/static-deploy.md
Expand Up @@ -40,7 +40,7 @@ $ npm run build
$ npm run preview
```

The `vite preview` command will boot up local static web server that serves the files from `dist` at http://localhost:5000. It's an easy way to check if the production build looks OK in your local environment.
The `vite preview` command will boot up local static web server that serves the files from `dist` at `http://localhost:4173`. It's an easy way to check if the production build looks OK in your local environment.

You may configure the port of the server py passing `--port` flag as an argument.

Expand All @@ -52,7 +52,7 @@ You may configure the port of the server py passing `--port` flag as an argument
}
```

Now the `preview` method will launch the server at http://localhost:8080.
Now the `preview` method will launch the server at `http://localhost:8080`.

## GitHub Pages

Expand Down Expand Up @@ -267,15 +267,30 @@ You can also deploy to a [custom domain](http://surge.sh/help/adding-a-custom-do

## Vercel

To deploy your Vite app with a [Vercel for Git](https://vercel.com/docs/git), make sure it has been pushed to a Git repository.
### Vercel CLI

Go to https://vercel.com/import/git and import the project into Vercel using your Git of choice (GitHub, GitLab or BitBucket). Follow the wizard to select the project root with the project's `package.json` and override the build step using `npm run build` and the output dir to be `./dist`
1. Install the [Vercel CLI](https://vercel.com/cli) and run `vercel` to deploy.
2. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
3. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))

![Override Vercel Configuration](../images/vercel-configuration.png)
```bash
$ npm i -g vercel
$ vercel init vite
Vercel CLI
> Success! Initialized "vite" example in ~/your-folder.
- To deploy, `cd vite` and run `vercel`.
```

### Vercel for Git

1. Push your code to your git repository (GitHub, GitLab, BitBucket).
2. [Import your Vite project](https://vercel.com/new) into Vercel.
3. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
4. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))

After your project has been imported, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly "main") will result in a Production Deployment.
After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/concepts/deployments/environments#preview), and all changes made to the Production Branch (commonly main) will result in a [Production Deployment](https://vercel.com/docs/concepts/deployments/environments#production).

Once deployed, you will get a URL to see your app live, such as the following: https://vite.vercel.app
Learn more about Vercel’s [Git Integration](https://vercel.com/docs/concepts/git).

## Azure Static Web Apps

Expand Down
22 changes: 22 additions & 0 deletions docs/public/cypress.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions package.json
Expand Up @@ -32,41 +32,41 @@
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.19.3",
"@microsoft/api-extractor": "^7.19.4",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.17",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.22",
"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "0.14.3",
"eslint": "^8.5.0",
"eslint-define-config": "^1.2.1",
"esbuild": "^0.14.14",
"eslint": "^8.8.0",
"eslint-define-config": "^1.2.4",
"eslint-plugin-node": "^11.1.0",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"jest": "^27.4.5",
"lint-staged": "^12.1.4",
"jest": "^27.5.1",
"lint-staged": "^12.3.3",
"minimist": "^1.2.5",
"node-fetch": "^2.6.6",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.17.1",
"playwright-chromium": "^1.18.1",
"prettier": "2.5.1",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
"rollup": "^2.59.0",
"semver": "^7.3.5",
"simple-git-hooks": "^2.7.0",
"sirv": "^2.0.0",
"ts-jest": "^27.1.2",
"sirv": "^2.0.2",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"typescript": "~4.5.4",
"vite": "workspace:*",
"vitepress": "^0.20.10"
"vitepress": "^0.21.6"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false",
Expand All @@ -83,7 +83,7 @@
"eslint --ext .ts"
]
},
"packageManager": "pnpm@6.24.4",
"packageManager": "pnpm@6.30.0",
"pnpm": {
"overrides": {
"vite": "workspace:*",
Expand Down
14 changes: 14 additions & 0 deletions packages/create-vite/CHANGELOG.md
@@ -1,3 +1,17 @@
# [2.8.0](https://github.com/vitejs/vite/compare/create-vite@2.7.2...create-vite@2.8.0) (2022-02-09)


### Bug Fixes

* **create-vite:** use `reset` for prompts for white bg color shell ([#6131](https://github.com/vitejs/vite/issues/6131)) ([dd3bbb8](https://github.com/vitejs/vite/commit/dd3bbb8e21aff812ec482f760e1abceb6bd67aef))


### Features

* **create-vite:** tsconfig support vite.config.ts ([#6324](https://github.com/vitejs/vite/issues/6324)) ([bfbdb22](https://github.com/vitejs/vite/commit/bfbdb2242e57cfba0309a88475a1f9cf2a50413f))



## [2.7.2](https://github.com/vitejs/vite/compare/create-vite@2.7.1...create-vite@2.7.2) (2021-12-13)


Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/package.json
@@ -1,6 +1,6 @@
{
"name": "create-vite",
"version": "2.7.2",
"version": "2.8.0",
"license": "MIT",
"author": "Evan You",
"bin": {
Expand Down
3 changes: 2 additions & 1 deletion packages/create-vite/template-lit-ts/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-lit-ts-starter",
"private": true,
"version": "0.0.0",
"main": "dist/my-element.es.js",
"exports": {
Expand All @@ -18,7 +19,7 @@
"lit": "^2.0.2"
},
"devDependencies": {
"vite": "^2.7.2",
"vite": "^2.8.0",
"typescript": "^4.5.4"
}
}
3 changes: 2 additions & 1 deletion packages/create-vite/template-lit/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-lit-starter",
"private": true,
"version": "0.0.0",
"main": "dist/my-element.es.js",
"exports": {
Expand All @@ -16,6 +17,6 @@
"lit": "^2.0.2"
},
"devDependencies": {
"vite": "^2.7.2"
"vite": "^2.8.0"
}
}
3 changes: 2 additions & 1 deletion packages/create-vite/template-preact-ts/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-preact-ts-starter",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand All @@ -12,6 +13,6 @@
"devDependencies": {
"@preact/preset-vite": "^2.1.5",
"typescript": "^4.5.4",
"vite": "^2.7.2"
"vite": "^2.8.0"
}
}
3 changes: 2 additions & 1 deletion packages/create-vite/template-preact/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-preact-starter",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand All @@ -11,6 +12,6 @@
},
"devDependencies": {
"@preact/preset-vite": "^2.1.5",
"vite": "^2.7.2"
"vite": "^2.8.0"
}
}
3 changes: 2 additions & 1 deletion packages/create-vite/template-react-ts/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-react-typescript-starter",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand All @@ -15,6 +16,6 @@
"@types/react-dom": "^17.0.10",
"@vitejs/plugin-react": "^1.0.7",
"typescript": "^4.5.4",
"vite": "^2.7.2"
"vite": "^2.8.0"
}
}
3 changes: 2 additions & 1 deletion packages/create-vite/template-react/package.json
@@ -1,5 +1,6 @@
{
"name": "vite-react-starter",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand All @@ -12,6 +13,6 @@
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
"vite": "^2.7.2"
"vite": "^2.8.0"
}
}

0 comments on commit 92f50a9

Please sign in to comment.