Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Apr 5, 2023
2 parents 89a11dc + 1ea38e2 commit 495fffd
Show file tree
Hide file tree
Showing 52 changed files with 721 additions and 503 deletions.
2 changes: 1 addition & 1 deletion docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default defineConfig({
- **Type:** `false | (sourcePath: string, sourcemapPath: string) => boolean`
- **Default:** `(sourcePath) => sourcePath.includes('node_modules')`

Whether or not to ignore source files in the server sourcemap, used to populate the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
Whether or not to ignore source files in the server sourcemap, used to populate the [`x_google_ignoreList` source map extension](https://developer.chrome.com/articles/x-google-ignore-list/).

`server.sourcemapIgnoreList` is the equivalent of [`build.rollupOptions.output.sourcemapIgnoreList`](https://rollupjs.org/configuration-options/#output-sourcemapignorelist) for the dev server. A difference between the two config options is that the rollup function is called with a relative path for `sourcePath` while `server.sourcemapIgnoreList` is called with an absolute path. During dev, most modules have the map and the source in the same folder, so the relative path for `sourcePath` is the file name itself. In these cases, absolute paths makes it convenient to be used instead.

Expand Down
2 changes: 1 addition & 1 deletion docs/config/shared-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Specify options to pass to CSS pre-processors. The file extensions are used as k
- `less` - [Options](https://lesscss.org/usage/#less-options).
- `styl`/`stylus` - Only [`define`](https://stylus-lang.com/docs/js.html#define-name-node) is supported, which can be passed as an object.

All preprocessor options also support the `additionalData` option, which can be used to inject extra code for each style content.
All preprocessor options also support the `additionalData` option, which can be used to inject extra code for each style content. Note that if you include actual styles and not just variables, those styles will be duplicated in the final bundle.

Example:

Expand Down
4 changes: 4 additions & 0 deletions docs/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ For example, you might see these errors.
> TypeError: Cannot create property 'foo' on boolean 'false'
If these code are used inside dependencies, you could use [`patch-package`](https://github.com/ds300/patch-package) (or [`yarn patch`](https://yarnpkg.com/cli/patch) or [`pnpm patch`](https://pnpm.io/cli/patch)) for an escape hatch.

### Browser extensions

Some browser extensions (like ad-blockers) may prevent the Vite client from sending requests to the Vite dev server. You may see a white screen without logged errors in this case. Try disabling extensions if you have this issue.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"prettier": "2.8.5",
"resolve": "^1.22.1",
"rimraf": "^4.4.0",
"rollup": "^3.20.0",
"rollup": "^3.20.2",
"simple-git-hooks": "^2.8.1",
"tslib": "^2.5.0",
"tsx": "^3.12.6",
Expand Down
19 changes: 12 additions & 7 deletions packages/create-vite/template-lit-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "bundler",
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"useDefineForClassFields": false,
"skipLibCheck": true
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact-ts/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from 'preact'
import { App } from './app'
import { App } from './app.tsx'
import './index.css'

render(<App />, document.getElementById('app') as HTMLElement)
21 changes: 13 additions & 8 deletions packages/create-vite/template-preact-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact"
"jsxImportSource": "preact",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from 'preact'
import { App } from './app'
import { App } from './app.jsx'
import './index.css'

render(<App />, document.getElementById('app'))
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
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
Expand Down
18 changes: 11 additions & 7 deletions packages/create-vite/template-react-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-react/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-vanilla-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './style.css'
import typescriptLogo from './typescript.svg'
import viteLogo from '/vite.svg'
import { setupCounter } from './counter'
import { setupCounter } from './counter.ts'

document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
Expand Down
16 changes: 10 additions & 6 deletions packages/create-vite/template-vanilla-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"strict": true,
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
21 changes: 14 additions & 7 deletions packages/create-vite/template-vue-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"strict": true,
"jsx": "preserve",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"esbuild": "^0.17.5",
"postcss": "^8.4.21",
"resolve": "^1.22.1",
"rollup": "^3.20.0"
"rollup": "^3.20.2"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
Expand Down
18 changes: 0 additions & 18 deletions packages/vite/rollupLicensePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import license from 'rollup-plugin-license'
import colors from 'picocolors'
import fg from 'fast-glob'
import resolve from 'resolve'
import type { Plugin } from 'rollup'

export default function licensePlugin(
Expand Down Expand Up @@ -66,21 +63,6 @@ export default function licensePlugin(
typeof repository === 'string' ? repository : repository.url
}\n`
}
if (!licenseText && name) {
try {
const pkgDir = path.dirname(
resolve.sync(path.join(name, 'package.json'), {
preserveSymlinks: false,
}),
)
const licenseFile = fg.sync(`${pkgDir}/LICENSE*`, {
caseSensitiveMatch: false,
})[0]
if (licenseFile) {
licenseText = fs.readFileSync(licenseFile, 'utf-8')
}
} catch {}
}
if (licenseText) {
text +=
'\n' +
Expand Down
55 changes: 46 additions & 9 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,61 @@ async function waitForSuccessfulPing(
) {
const pingHostProtocol = socketProtocol === 'wss' ? 'https' : 'http'

// eslint-disable-next-line no-constant-condition
while (true) {
const ping = async () => {
// A fetch on a websocket URL will return a successful promise with status 400,
// but will reject a networking error.
// When running on middleware mode, it returns status 426, and an cors error happens if mode is not no-cors
try {
// A fetch on a websocket URL will return a successful promise with status 400,
// but will reject a networking error.
// When running on middleware mode, it returns status 426, and an cors error happens if mode is not no-cors
await fetch(`${pingHostProtocol}://${hostAndPath}`, {
mode: 'no-cors',
})
break
} catch (e) {
// wait ms before attempting to ping again
await new Promise((resolve) => setTimeout(resolve, ms))
return true
} catch {}
return false
}

if (await ping()) {
return
}
await wait(ms)

// eslint-disable-next-line no-constant-condition
while (true) {
if (document.visibilityState === 'visible') {
if (await ping()) {
break
}
await wait(ms)
} else {
await waitForWindowShow()
}
}
}

function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

function waitForWindowShow() {
return new Promise<void>((resolve) => {
const onChange = async () => {
if (document.visibilityState === 'visible') {
resolve()
document.removeEventListener('visibilitychange', onChange)
}
}
document.addEventListener('visibilitychange', onChange)
})
}

const sheetsMap = new Map<string, HTMLStyleElement>()

// collect existing style elements that may have been inserted during SSR
// to avoid FOUC or duplicate styles
document.querySelectorAll('style[data-vite-dev-id]').forEach((el) => {
sheetsMap.set(el.getAttribute('data-vite-dev-id')!, el as HTMLStyleElement)
})

// all css imports should be inserted at the same position
// because after build it will be a single css file
let lastInsertedStyle: HTMLStyleElement | undefined
Expand Down
Loading

0 comments on commit 495fffd

Please sign in to comment.