Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed May 21, 2022
2 parents 2228aae + f4d6262 commit 7caec7c
Show file tree
Hide file tree
Showing 130 changed files with 1,750 additions and 441 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = defineConfig({
{ prefer: 'type-imports' }
],

'import/no-duplicates': 'error',
'import/order': 'error',
'sort-imports': [
'error',
Expand All @@ -114,6 +115,12 @@ module.exports = defineConfig({
'node/no-extraneous-import': 'off'
}
},
{
files: ['packages/plugin-*/**/*'],
rules: {
'no-restricted-globals': ['error', 'require', '__dirname', '__filename']
}
},
{
files: ['playground/**'],
rules: {
Expand Down
69 changes: 41 additions & 28 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,42 @@ import { defineConfig } from 'vitepress'
export default defineConfig({
title: 'Vite',
description: 'Next Generation Frontend Tooling',
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],

head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }],

// TODO: This is neeeded to get smooth dark mode appearance on initial
// load. And this will be gone when VitePress figures out how to handle
// this in core.
[
'script',
{},
`
;(() => {
const saved = localStorage.getItem('vitepress-theme-appearance')
const prefereDark = window.matchMedia('(prefers-color-scheme: dark)').matches
if (!saved || saved === 'auto' ? prefereDark : saved === 'dark') {
document.documentElement.classList.add('dark')
}
})()
`
]
],

vue: {
reactivityTransform: true
},

themeConfig: {
repo: 'vitejs/vite',
logo: '/logo.svg',
docsDir: 'docs',
docsBranch: 'main',
editLinks: true,
editLinkText: 'Suggest changes to this page',

editLink: {
repo: 'vitejs/vite',
branch: 'main',
dir: 'docs',
text: 'Suggest changes to this page'
},

algolia: {
apiKey: 'b573aa848fd57fb47d693b531297403c',
Expand All @@ -28,6 +53,14 @@ export default defineConfig({
placement: 'vitejsdev'
},

localeLinks: {
text: 'English',
items: [
{ text: '简体中文', link: 'https://cn.vitejs.dev' },
{ text: '日本語', link: 'https://ja.vitejs.dev' }
]
},

nav: [
{ text: 'Guide', link: '/guide/' },
{ text: 'Config', link: '/config/' },
Expand Down Expand Up @@ -69,34 +102,14 @@ export default defineConfig({
link: 'https://v2.vitejs.dev'
}
]
},
{
text: 'Languages',
items: [
{
text: 'English',
link: 'https://vitejs.dev'
},
{
text: '简体中文',
link: 'https://cn.vitejs.dev'
},
{
text: '日本語',
link: 'https://ja.vitejs.dev'
}
]
}
],

sidebar: {
'/config/': 'auto',
'/plugins': 'auto',
// catch-all fallback
'/': [
{
text: 'Guide',
children: [
items: [
{
text: 'Why Vite',
link: '/guide/why'
Expand Down Expand Up @@ -153,7 +166,7 @@ export default defineConfig({
},
{
text: 'APIs',
children: [
items: [
{
text: 'Plugin API',
link: '/guide/api-plugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Theme from 'vitepress/theme'
import { h } from 'vue'
import Theme from 'vitepress/theme'
import SponsorsSidebar from './SponsorsSidebar.vue'
import './custom.css'
import './styles/vars.css'
import './styles/custom.css'

export default {
...Theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
display: none;
}

:root {
--c-brand: #646cff;
--c-brand-light: #747bff;
}

.custom-block.tip {
border-color: var(--c-brand-light);
border-color: var(--vp-c-brand-light);
}

.DocSearch {
--docsearch-primary-color: var(--c-brand) !important;
--docsearch-primary-color: var(--vp-c-brand) !important;
}

#play-vite-audio {
Expand Down
5 changes: 5 additions & 0 deletions docs/.vitepress/theme/styles/vars.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:root {
--vp-c-brand: #646cff;
--vp-c-brand-light: #747bff;
--vp-c-brand-dark: #535bf2;
}
5 changes: 2 additions & 3 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ createServer()

### server.fs.deny

- **Experimental**
- **Type:** `string[]`

Blocklist for sensitive files being restricted to be served by Vite dev server.
Expand Down Expand Up @@ -741,11 +740,11 @@ export default defineConfig({
- **Default:** `'modules'`
- **Related:** [Browser Compatibility](/guide/build#browser-compatibility)

Browser compatibility target for the final bundle. The default value is a Vite special value, `'modules'`, which targets [browsers with native ES module support](https://caniuse.com/es6-module).
Browser compatibility target for the final bundle. The default value is a Vite special value, `'modules'`, which targets browsers with [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) support.

Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:

- If the [`build.minify`](#build-minify) option is `'terser'`, `'esnext'` will be forced down to `'es2019'`.
- If the [`build.minify`](#build-minify) option is `'terser'`, `'esnext'` will be forced down to `'es2021'`.
- In other cases, it will perform no transpilation at all.

The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be a ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings.
Expand Down
6 changes: 4 additions & 2 deletions docs/guide/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const { createServer } = require('vite')
})()
```

::: tip NOTE
When using `createServer` and `build` in the same Node.js process, both functions rely on `process.env.`<wbr>`NODE_ENV` to work properly, which also depends on the `mode` config option. To prevent conflicting behavior, set `process.env.`<wbr>`NODE_ENV` or the `mode` of the two APIs to `development`. Otherwise, you can spawn a child process to run the APIs separately.
:::

## `InlineConfig`

The `InlineConfig` interface extends `UserConfig` with additional properties:
Expand Down Expand Up @@ -148,8 +152,6 @@ const { build } = require('vite')

## `preview`

**Experimental**

**Type Signature:**

```ts
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ const imgUrl = new URL(imagePath, import.meta.url).href
This pattern does not work if you are using Vite for Server-Side Rendering, because `import.meta.url` have different semantics in browsers vs. Node.js. The server bundle also cannot determine the client host URL ahead of time.
:::
::: warning Esbuild target config is necessary
This pattern needs esbuild target to be set to `es2020` or higher. `[email protected]` use `es2019` as default target. Set [build-target](https://vitejs.dev/config/#build-target) and [optimizedeps.esbuildoptions.target](https://vitejs.dev/config/#optimizedeps-esbuildoptions) to `es2020` or higher if you intend to use this partten.
::: warning `target` needs to be `es2020` or higher
This pattern will not work if [build-target](https://vitejs.dev/config/#build-target) or [optimizedeps.esbuildoptions.target](https://vitejs.dev/config/#optimizedeps-esbuildoptions) is set to a value lower than `es2020`.
:::
9 changes: 5 additions & 4 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ When it is time to deploy your app for production, simply run the `vite build` c

## Browser Compatibility

The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the [native ESM script tag](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import). As a reference, Vite uses this [browserslist](https://github.com/browserslist/browserslist) query:
The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) and [`import.meta`](https://caniuse.com/mdn-javascript_statements_import_meta):

```
defaults and supports es6-module and supports es6-module-dynamic-import, not opera > 0, not samsung > 0, not and_qq > 0
```
- Chrome >=87
- Firefox >=78
- Safari >=13
- Edge >=88

You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`.

Expand Down
13 changes: 9 additions & 4 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ Note that variables only represent file names one level deep. If `file` is `'foo

## WebAssembly

Pre-compiled `.wasm` files can be directly imported - the default export will be an initialization function that returns a Promise of the exports object of the wasm instance:
Pre-compiled `.wasm` files can be imported with `?init` - the default export will be an initialization function that returns a Promise of the wasm instance:

```js
import init from './example.wasm'
import init from './example.wasm?init'

init().then((exports) => {
exports.test()
init().then((instance) => {
instance.exports.test()
})
```

Expand All @@ -461,6 +461,11 @@ init({

In the production build, `.wasm` files smaller than `assetInlineLimit` will be inlined as base64 strings. Otherwise, they will be copied to the dist directory as an asset and fetched on-demand.

::: warning
[ES Module Integration Proposal for WebAssembly](https://github.com/WebAssembly/esm-integration) is not currently supported.
Use [`vite-plugin-wasm`](https://github.com/Menci/vite-plugin-wasm) or other community plugins to handle this.
:::

## Web Workers

### Import with Constructors
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can learn more about the rationale behind the project in the [Why Vite](./wh

## Browser Support

- The default build targets browsers that support both [native ESM via script tags](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details.
- The default build targets browsers that support both [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details.

## Trying Vite Online

Expand Down Expand Up @@ -145,4 +145,4 @@ Then go to your Vite based project and run `pnpm link --global vite` (or the pac

## Community

If you have questions or need help, reach out to the community at [Discord](https://discord.gg/4cmKdMfpU5) and [GitHub Discussions](https://github.com/vitejs/vite/discussions).
If you have questions or need help, reach out to the community at [Discord](https://chat.vitejs.dev) and [GitHub Discussions](https://github.com/vitejs/vite/discussions).
2 changes: 1 addition & 1 deletion docs/guide/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Our scripts in `package.json` will look like this:
Note the `--ssr` flag which indicates this is an SSR build. It should also specify the SSR entry.
Then, in `server.js` we need to add some production specific logic by checking `process.env.NODE_ENV`:
Then, in `server.js` we need to add some production specific logic by checking `process.env.`<wbr>`NODE_ENV`:
- Instead of reading the root `index.html`, use the `dist/client/index.html` as the template instead, since it contains the correct asset links to the client build.
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ features:
footer: MIT Licensed | Copyright © 2019-present Evan You & Vite Contributors
---

> TODO: Home Page feature is not ready in VitePress Next just yet! So this page looks broken for now.
<script setup>
import SponsorsGroup from './.vitepress/theme/SponsorsGroup.vue'
</script>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.21.1",
"pnpm": "^7.1.2",
"prettier": "2.6.2",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
Expand All @@ -83,7 +84,7 @@
"typescript": "^4.6.4",
"unbuild": "^0.7.4",
"vite": "workspace:*",
"vitepress": "^0.22.4",
"vitepress": "1.0.0-draft.1",
"vitest": "^0.12.4",
"vue": "^3.2.33"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/create-vite/template-lit-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "esnext",
"lib": ["es2017", "dom", "dom.iterable"],
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./types",
Expand All @@ -10,7 +10,7 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"moduleResolution": "Node",
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-lit-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
4 changes: 2 additions & 2 deletions packages/create-vite/template-preact-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-react-ts/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-react-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
4 changes: 2 additions & 2 deletions packages/create-vite/template-svelte-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "esnext",
"target": "ESNext",
"useDefineForClassFields": true,
"module": "esnext",
"module": "ESNext",
"resolveJsonModule": true,
"baseUrl": ".",
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-svelte-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
Loading

0 comments on commit 7caec7c

Please sign in to comment.