From 21dd28dd648b6d043eaad2f31efdd379e5134635 Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 3 May 2023 10:29:51 +0200 Subject: [PATCH 01/75] docs: document /index.html as importer during dev (#12911) Co-authored-by: Bjorn Lu --- docs/guide/api-plugin.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index d5f92bad9ad879..ebcdade803e2ea 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -159,7 +159,9 @@ The following hooks are called on each incoming module request: - [`load`](https://rollupjs.org/plugin-development/#load) - [`transform`](https://rollupjs.org/plugin-development/#transform) -They also have an extended `options` parameter with additional Vite-specific properties. You can read more in the [SSR documentation](/guide/ssr#ssr-specific-plugin-logic). +These hooks also have an extended `options` parameter with additional Vite-specific properties. You can read more in the [SSR documentation](/guide/ssr#ssr-specific-plugin-logic). + +Some `resolveId` calls' `importer` value may be an absolute path for a generic `index.html` at root as it's not always possible to derive the actual importer due to Vite's unbundled dev server pattern. For imports handled within Vite's resolve pipeline, the importer can be tracked during the import analysis phase, providing the correct `importer` value. The following hooks are called when the server is closed: From 7089528b7c740de7fafa715c01c368271afc8e6b Mon Sep 17 00:00:00 2001 From: sun0day Date: Thu, 4 May 2023 12:39:41 +0800 Subject: [PATCH 02/75] fix(assetImportMetaUrl): reserve dynamic template literal query params (#13034) --- .../src/node/plugins/assetImportMetaUrl.ts | 18 ++++++++++++++-- playground/assets/__tests__/assets.spec.ts | 11 ++++++++++ playground/assets/index.html | 21 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index 6872de5249e014..d16b1ad7540b64 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -5,6 +5,7 @@ import type { Plugin } from '../plugin' import type { ResolvedConfig } from '../config' import type { ResolveFn } from '../' import { + injectQuery, isParentDirectory, normalizePath, slash, @@ -55,7 +56,12 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { // potential dynamic template string if (rawUrl[0] === '`' && rawUrl.includes('${')) { - const ast = this.parse(rawUrl) + let [pureUrl, queryString = ''] = rawUrl.split('?') + if (queryString) { + pureUrl += '`' + queryString = '?' + queryString.slice(0, -1) + } + const ast = this.parse(pureUrl) const templateLiteral = (ast as any).body[0].expression if (templateLiteral.expressions.length) { const pattern = buildGlobPattern(templateLiteral) @@ -65,6 +71,12 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { continue } + const globOptions = { + eager: true, + import: 'default', + // A hack to allow 'as' & 'query' exist at the same time + query: injectQuery(queryString, 'url'), + } // Note: native import.meta.url is not supported in the baseline // target so we use the global location here. It can be // window.location or self.location in case it is used in a Web Worker. @@ -74,7 +86,9 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { index + exp.length, `new URL((import.meta.glob(${JSON.stringify( pattern, - )}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, + )}, ${JSON.stringify( + globOptions, + )}))[${pureUrl}], self.location)`, ) continue } diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index 3aa3a9ab3189dd..29d56820c6c4bf 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -324,6 +324,17 @@ test('new URL(`${dynamic}`, import.meta.url)', async () => { ) }) +test('new URL(`./${dynamic}?abc`, import.meta.url)', async () => { + expect(await page.textContent('.dynamic-import-meta-url-1-query')).toMatch( + isBuild ? 'data:image/png;base64' : '/foo/nested/icon.png?abc', + ) + expect(await page.textContent('.dynamic-import-meta-url-2-query')).toMatch( + isBuild + ? /\/foo\/assets\/asset-\w{8}\.png\?abc/ + : '/foo/nested/asset.png?abc', + ) +}) + test('new URL(`non-existent`, import.meta.url)', async () => { expect(await page.textContent('.non-existent-import-meta-url')).toMatch( new URL('non-existent', page.url()).pathname, diff --git a/playground/assets/index.html b/playground/assets/index.html index 57caa90f4f552d..b9e857398b6c35 100644 --- a/playground/assets/index.html +++ b/playground/assets/index.html @@ -221,6 +221,16 @@

new URL(`./${dynamic}`, import.meta.url,) (with comma)

+

new URL(`./${dynamic}?abc`, import.meta.url)

+

+ + +

+

+ + +

+

new URL(`non-existent`, import.meta.url)

@@ -432,6 +442,17 @@

assets in noscript

testDynamicImportMetaUrlWithComma('icon', 1) testDynamicImportMetaUrlWithComma('asset', 2) + function testDynamicImportMetaUrlWithQuery(name, i) { + // prettier-ignore + const metaUrl = new URL(`./nested/${name}.png?abc`, import.meta.url,) + text(`.dynamic-import-meta-url-${i}-query`, metaUrl) + document.querySelector(`.dynamic-import-meta-url-img-${i}-query`).src = + metaUrl + } + + testDynamicImportMetaUrlWithQuery('icon', 1) + testDynamicImportMetaUrlWithQuery('asset', 2) + { const name = 'test' const js = new URL(`./nested/${name}.js`, import.meta.url).href From 8a8ea1d3aed9db67da47e610d3c66b831815f898 Mon Sep 17 00:00:00 2001 From: Chris Thomas Date: Thu, 4 May 2023 02:55:17 -0400 Subject: [PATCH 03/75] fix(ssr): ignore __esModule for ssrExportAll (#13084) --- packages/vite/src/node/ssr/ssrModuleLoader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 2f9e71f55569bd..09a9b8817cc380 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -189,7 +189,7 @@ async function instantiateModule( function ssrExportAll(sourceModule: any) { for (const key in sourceModule) { - if (key !== 'default') { + if (key !== 'default' && key !== '__esModule') { Object.defineProperty(ssrModule, key, { enumerable: true, configurable: true, From 9041e19585dc2679d558ec51e77fd1ea1bacdb2b Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 4 May 2023 10:58:43 +0200 Subject: [PATCH 04/75] fix: unwrapId and pass ssr flag when adding to moduleGraph in this.load (#13083) --- packages/vite/src/node/server/pluginContainer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 38c057bbbf8c29..ce851e8d2b24ec 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -76,6 +76,7 @@ import { numberToPos, prettifyUrl, timeFrom, + unwrapId, } from '../utils' import { FS_PREFIX } from '../constants' import type { ResolvedConfig } from '../config' @@ -313,7 +314,7 @@ export async function createPluginContainer( } & Partial>, ): Promise { // We may not have added this to our module graph yet, so ensure it exists - await moduleGraph?.ensureEntryFromUrl(options.id) + await moduleGraph?.ensureEntryFromUrl(unwrapId(options.id), this.ssr) // Not all options passed to this function make sense in the context of loading individual files, // but we can at least update the module info properties we support updateModuleInfo(options.id, options) From d95a9af5c1aa9babecd710ef2d341a7839b41daf Mon Sep 17 00:00:00 2001 From: sun0day Date: Fri, 5 May 2023 11:55:11 +0800 Subject: [PATCH 05/75] fix(debug): skip filter object args (#13098) --- packages/vite/src/node/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index d962bccc8eee6e..effea7fb34a126 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -169,7 +169,7 @@ export function createDebugger( if (enabled) { return (...args: [string, ...any[]]) => { - if (!filter || args.some((a) => a?.includes(filter))) { + if (!filter || args.some((a) => a?.includes?.(filter))) { log(...args) } } From 91d7b678ce6a397d01cd1351ce29de2f50f9d775 Mon Sep 17 00:00:00 2001 From: Michal Kalita Date: Fri, 5 May 2023 11:03:26 +0200 Subject: [PATCH 06/75] fix: location is not defined error in cleanScssBugUrl (#13100) --- packages/vite/src/node/plugins/css.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 7366c1b093799d..c7856b7e55c5d1 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1600,6 +1600,7 @@ function cleanScssBugUrl(url: string) { if ( // check bug via `window` and `location` global typeof window !== 'undefined' && + typeof location !== 'undefined' && typeof location?.href === 'string' ) { const prefix = location.href.replace(/\/$/, '') From 8a37de604f18b5053be717e232e2b1353addf8d0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 5 May 2023 17:59:06 +0800 Subject: [PATCH 07/75] fix(scan): handle html script tag attributes that contain ">" (#13101) --- packages/vite/src/node/optimizer/scan.ts | 14 ++++++++------ playground/optimize-deps/generics.vue | 22 ++++++++++++++++++++++ playground/optimize-deps/index.html | 1 + playground/optimize-deps/vite.config.js | 5 +++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 playground/optimize-deps/generics.vue diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 5571d031245f6d..3c592cec499de5 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -246,9 +246,8 @@ function globEntries(pattern: string | string[], config: ResolvedConfig) { }) } -const scriptModuleRE = - /(]+type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gis -export const scriptRE = /(]*>|>))(.*?)<\/script>/gis +export const scriptRE = + /(=\s]+))?)*\s*>)(.*?)<\/script>/gis export const commentRE = //gs const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i @@ -378,12 +377,11 @@ function esbuildScanPlugin( // Avoid matching the content of the comment raw = raw.replace(commentRE, '') const isHtml = path.endsWith('.html') - const regex = isHtml ? scriptModuleRE : scriptRE - regex.lastIndex = 0 + scriptRE.lastIndex = 0 let js = '' let scriptId = 0 let match: RegExpExecArray | null - while ((match = regex.exec(raw))) { + while ((match = scriptRE.exec(raw))) { const [, openTag, content] = match const typeMatch = openTag.match(typeRE) const type = @@ -391,6 +389,10 @@ function esbuildScanPlugin( const langMatch = openTag.match(langRE) const lang = langMatch && (langMatch[1] || langMatch[2] || langMatch[3]) + // skip non type module script + if (isHtml && type !== 'module') { + continue + } // skip type="application/ld+json" and other non-JS types if ( type && diff --git a/playground/optimize-deps/generics.vue b/playground/optimize-deps/generics.vue new file mode 100644 index 00000000000000..13e17ce1c12d6a --- /dev/null +++ b/playground/optimize-deps/generics.vue @@ -0,0 +1,22 @@ + + + + + + + diff --git a/playground/optimize-deps/index.html b/playground/optimize-deps/index.html index 8c5719075650ce..a07e6a17798154 100644 --- a/playground/optimize-deps/index.html +++ b/playground/optimize-deps/index.html @@ -165,6 +165,7 @@

Pre bundle css require

) import './index.astro' + import './generics.vue' // All these imports should end up resolved to the same URL (same ?v= injected on them) import { add as addFromDirectAbsolutePath } from '/node_modules/@vitejs/test-dep-non-optimized/index.js' diff --git a/playground/optimize-deps/vite.config.js b/playground/optimize-deps/vite.config.js index 7eb4c5b10c3101..04ba79b5a2e38d 100644 --- a/playground/optimize-deps/vite.config.js +++ b/playground/optimize-deps/vite.config.js @@ -121,6 +121,11 @@ export default defineComponent({ `.trim(), } } + + // fallback to empty module for other vue files + if (id.endsWith('.vue')) { + return { code: `export default {}` } + } }, } } From 775505d748d8cd076e823a80d47647ca8e6badf6 Mon Sep 17 00:00:00 2001 From: patak Date: Fri, 5 May 2023 12:18:01 +0200 Subject: [PATCH 08/75] release: v4.3.5 --- packages/vite/CHANGELOG.md | 11 +++++++++++ packages/vite/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index d1257f1c9695b6..fb2a6e981f3270 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,14 @@ +## 4.3.5 (2023-05-05) + +* fix: location is not defined error in cleanScssBugUrl (#13100) ([91d7b67](https://github.com/vitejs/vite/commit/91d7b67)), closes [#13100](https://github.com/vitejs/vite/issues/13100) +* fix: unwrapId and pass ssr flag when adding to moduleGraph in this.load (#13083) ([9041e19](https://github.com/vitejs/vite/commit/9041e19)), closes [#13083](https://github.com/vitejs/vite/issues/13083) +* fix(assetImportMetaUrl): reserve dynamic template literal query params (#13034) ([7089528](https://github.com/vitejs/vite/commit/7089528)), closes [#13034](https://github.com/vitejs/vite/issues/13034) +* fix(debug): skip filter object args (#13098) ([d95a9af](https://github.com/vitejs/vite/commit/d95a9af)), closes [#13098](https://github.com/vitejs/vite/issues/13098) +* fix(scan): handle html script tag attributes that contain ">" (#13101) ([8a37de6](https://github.com/vitejs/vite/commit/8a37de6)), closes [#13101](https://github.com/vitejs/vite/issues/13101) +* fix(ssr): ignore __esModule for ssrExportAll (#13084) ([8a8ea1d](https://github.com/vitejs/vite/commit/8a8ea1d)), closes [#13084](https://github.com/vitejs/vite/issues/13084) + + + ## 4.3.4 (2023-05-02) * fix(define): incorrect raw expression value type in build (#13003) ([8f4cf07](https://github.com/vitejs/vite/commit/8f4cf07)), closes [#13003](https://github.com/vitejs/vite/issues/13003) diff --git a/packages/vite/package.json b/packages/vite/package.json index 3838a5530a6e2a..ae3901698547cc 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "4.3.4", + "version": "4.3.5", "type": "module", "license": "MIT", "author": "Evan You", From c63ba3fa08a64d75bfffa6885dc4c44875b9c5ba Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 5 May 2023 17:18:18 +0200 Subject: [PATCH 09/75] fix: upgrade svelte-check preventing unmet peer deps errors (#13103) --- packages/create-vite/template-svelte-ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json index 5669fca81962d0..3e613d9fc7b00d 100644 --- a/packages/create-vite/template-svelte-ts/package.json +++ b/packages/create-vite/template-svelte-ts/package.json @@ -13,7 +13,7 @@ "@sveltejs/vite-plugin-svelte": "^2.0.4", "@tsconfig/svelte": "^4.0.1", "svelte": "^3.58.0", - "svelte-check": "^2.10.3", + "svelte-check": "^3.3.1", "tslib": "^2.5.0", "typescript": "^5.0.2", "vite": "^4.3.2" From d63129b5f028646596bd5c57d2832eaf441c77b7 Mon Sep 17 00:00:00 2001 From: Li Lin Date: Mon, 8 May 2023 16:35:08 +0800 Subject: [PATCH 10/75] fix(build): declare moduleSideEffects for vite:modulepreload-polyfill (#13099) --- .../modulePreloadPolyfill.spec.ts.snap | 51 ++++++++++++++++++ .../modulePreloadPolyfill.spec.ts | 53 +++++++++++++++++++ .../src/node/plugins/modulePreloadPolyfill.ts | 2 +- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap create mode 100644 packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/modulePreloadPolyfill.spec.ts diff --git a/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap b/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap new file mode 100644 index 00000000000000..7034be03a7c4db --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap @@ -0,0 +1,51 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`load > doesn't load modulepreload polyfill when format is cjs 1`] = ` +"\\"use strict\\"; +" +`; + +exports[`load > loads modulepreload polyfill 1`] = ` +"(function polyfill() { + const relList = document.createElement(\\"link\\").relList; + if (relList && relList.supports && relList.supports(\\"modulepreload\\")) { + return; + } + for (const link of document.querySelectorAll('link[rel=\\"modulepreload\\"]')) { + processPreload(link); + } + new MutationObserver((mutations) => { + for (const mutation of mutations) { + if (mutation.type !== \\"childList\\") { + continue; + } + for (const node of mutation.addedNodes) { + if (node.tagName === \\"LINK\\" && node.rel === \\"modulepreload\\") + processPreload(node); + } + } + }).observe(document, { childList: true, subtree: true }); + function getFetchOpts(link) { + const fetchOpts = {}; + if (link.integrity) + fetchOpts.integrity = link.integrity; + if (link.referrerPolicy) + fetchOpts.referrerPolicy = link.referrerPolicy; + if (link.crossOrigin === \\"use-credentials\\") + fetchOpts.credentials = \\"include\\"; + else if (link.crossOrigin === \\"anonymous\\") + fetchOpts.credentials = \\"omit\\"; + else + fetchOpts.credentials = \\"same-origin\\"; + return fetchOpts; + } + function processPreload(link) { + if (link.ep) + return; + link.ep = true; + const fetchOpts = getFetchOpts(link); + fetch(link.href, fetchOpts); + } +})(); +" +`; diff --git a/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/modulePreloadPolyfill.spec.ts b/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/modulePreloadPolyfill.spec.ts new file mode 100644 index 00000000000000..3b24fbd5203baa --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/modulePreloadPolyfill.spec.ts @@ -0,0 +1,53 @@ +import { describe, it } from 'vitest' +import type { ModuleFormat, RollupOutput } from 'rollup' +import { build } from '../../../build' +import { modulePreloadPolyfillId } from '../../../plugins/modulePreloadPolyfill' + +const buildProject = ({ format = 'es' as ModuleFormat } = {}) => + build({ + logLevel: 'silent', + build: { + write: false, + rollupOptions: { + input: 'main.js', + output: { + format, + }, + treeshake: { + moduleSideEffects: false, + }, + }, + minify: false, + }, + plugins: [ + { + name: 'test', + resolveId(id) { + if (id === 'main.js') { + return `\0${id}` + } + }, + load(id) { + if (id === '\0main.js') { + return `import '${modulePreloadPolyfillId}'` + } + }, + }, + ], + }) as Promise + +describe('load', () => { + it('loads modulepreload polyfill', async ({ expect }) => { + const { output } = await buildProject() + expect(output).toHaveLength(1) + expect(output[0].code).toMatchSnapshot() + }) + + it("doesn't load modulepreload polyfill when format is cjs", async ({ + expect, + }) => { + const { output } = await buildProject({ format: 'cjs' }) + expect(output).toHaveLength(1) + expect(output[0].code).toMatchSnapshot() + }) +}) diff --git a/packages/vite/src/node/plugins/modulePreloadPolyfill.ts b/packages/vite/src/node/plugins/modulePreloadPolyfill.ts index 0f1ef11cf26f5e..ede79c8b882f77 100644 --- a/packages/vite/src/node/plugins/modulePreloadPolyfill.ts +++ b/packages/vite/src/node/plugins/modulePreloadPolyfill.ts @@ -25,7 +25,7 @@ export function modulePreloadPolyfillPlugin(config: ResolvedConfig): Plugin { if (!polyfillString) { polyfillString = `${isModernFlag}&&(${polyfill.toString()}());` } - return polyfillString + return { code: polyfillString, moduleSideEffects: true } } }, } From 87e1f5838263d53d8ccf856926ff0a627d763b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B7=BC=E7=84=B1=5Frawbin?= Date: Mon, 8 May 2023 22:12:42 +0800 Subject: [PATCH 11/75] fix: avoid dev-server crash when ws proxy error (#12829) --- packages/vite/src/node/server/middlewares/proxy.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index f07b93e0746223..66f99f94f0609d 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -79,6 +79,19 @@ export function proxyMiddleware( res.end() } }) + + proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => { + socket.on('error', (err) => { + config.logger.error( + `${colors.red(`ws proxy socket error:`)}\n${err.stack}`, + { + timestamp: true, + error: err, + }, + ) + }) + }) + // clone before saving because http-proxy mutates the options proxies[context] = [proxy, { ...opts }] }) From d06cc421031dcb6c54abb12039dc6689c5a46b73 Mon Sep 17 00:00:00 2001 From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Date: Mon, 8 May 2023 21:33:10 +0545 Subject: [PATCH 12/75] fix(server): intercept ping requests (#13117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- packages/vite/src/client/client.ts | 5 +++++ packages/vite/src/node/server/index.ts | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index ed1cab3eb17c2e..0abf5bccef0944 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -321,6 +321,11 @@ async function waitForSuccessfulPing( try { await fetch(`${pingHostProtocol}://${hostAndPath}`, { mode: 'no-cors', + headers: { + // Custom headers won't be included in a request with no-cors so (ab)use one of the + // safelisted headers to identify the ping request + Accept: 'text/x-vite-ping', + }, }) return true } catch {} diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 0831cd01fe3743..541372996c2f4b 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -608,6 +608,16 @@ export async function _createServer( // open in editor support middlewares.use('/__open-in-editor', launchEditorMiddleware()) + // ping request handler + // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` + middlewares.use(function viteHMRPingMiddleware(req, res, next) { + if (req.headers['accept'] === 'text/x-vite-ping') { + res.writeHead(204).end() + } else { + next() + } + }) + // serve static files under /public // this applies before the transform middleware so that these files are served // as-is without transforms. From a8c7eb24a2b7d8dc765d59758e2c6b930eb90af1 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Tue, 9 May 2023 17:33:34 +0800 Subject: [PATCH 13/75] test: migrate playgrounds to ESM (#13094) --- .eslintrc.cjs | 15 ++++++++ playground/alias/package.json | 1 + playground/alias/vite.config.js | 3 ++ playground/assets-sanitize/package.json | 1 + playground/assets/package.json | 1 + playground/backend-integration/package.json | 1 + .../backend-integration/postcss.config.js | 9 +++-- .../backend-integration/tailwind.config.js | 4 ++- playground/build-old/package.json | 1 + playground/cli/package.json | 1 + playground/config/__tests__/load.spec.ts | 2 +- playground/config/packages/entry/package.json | 1 + .../plugin-module-condition/package.json | 1 + playground/config/packages/siblings/foo.ts | 4 +-- .../config/packages/siblings/package.json | 1 + playground/css-codesplit-cjs/package.json | 1 + playground/css-codesplit/package.json | 1 + playground/css-dynamic-import/package.json | 1 + playground/css-sourcemap/package.json | 1 + playground/css/package.json | 1 + .../css/postcss-caching/blue-app/package.json | 1 + .../blue-app/postcss.config.js | 2 +- .../postcss-caching/green-app/package.json | 1 + .../green-app/postcss.config.js | 2 +- playground/css/postcss.config.js | 15 ++++---- playground/data-uri/package.json | 1 + playground/define/package.json | 1 + playground/dynamic-import/package.json | 1 + playground/dynamic-import/vite.config.js | 4 +-- playground/env-nested/package.json | 1 + playground/env/package.json | 1 + playground/extensions/package.json | 1 + playground/external/package.json | 1 + playground/fs-serve/package.json | 1 + playground/glob-import/package.json | 1 + playground/hmr/package.json | 1 + playground/hmr/tsconfig.json | 16 --------- playground/html/package.json | 1 + playground/import-assertion/package.json | 1 + playground/js-sourcemap/package.json | 1 + .../json/__tests__/{ => csr}/json.spec.ts | 8 ++--- playground/json/__tests__/ssr/json.spec.ts | 20 +++++++++++ playground/json/__tests__/ssr/serve.ts | 35 +++++++++++++++++++ playground/json/package.json | 3 +- playground/json/server.js | 25 ++++++------- .../legacy/__tests__/client-and-ssr/serve.ts | 2 +- playground/legacy/__tests__/ssr/serve.ts | 2 +- playground/legacy/package.json | 1 + playground/lib/__tests__/lib.spec.ts | 12 ++++--- playground/lib/index.dist.html | 4 +-- playground/lib/package.json | 1 + playground/minify/package.json | 1 + playground/multiple-entrypoints/package.json | 1 + playground/nested-deps/package.json | 1 + playground/object-hooks/package.json | 1 + .../optimize-deps-no-discovery/package.json | 1 + playground/optimize-deps/package.json | 1 + playground/optimize-deps/vite.config.js | 2 ++ .../__test__/optimize-missing-deps.spec.ts | 4 +-- .../optimize-missing-deps/__test__/serve.ts | 2 +- playground/optimize-missing-deps/package.json | 1 + playground/optimize-missing-deps/server.js | 15 ++++---- playground/package.json | 1 + playground/preload/package.json | 1 + playground/preserve-symlinks/package.json | 1 + playground/resolve-config/package.json | 1 + playground/resolve-linked/package.json | 1 + .../resolve/{config-dep.js => config-dep.cjs} | 0 playground/resolve/package.json | 1 + playground/resolve/vite.config.js | 2 +- playground/ssr-deps/package.json | 2 +- playground/ssr-resolve/package.json | 1 + playground/tailwind-sourcemap/package.json | 1 + .../tailwind-sourcemap/postcss.config.js | 8 ++++- .../tailwind-sourcemap/tailwind.config.js | 4 ++- playground/tailwind/tailwind.config.js | 2 ++ playground/test-utils.ts | 1 + playground/transform-plugin/package.json | 1 + .../tsconfig-json-load-error/package.json | 1 + playground/tsconfig-json/package.json | 1 + playground/vitestSetup.ts | 2 +- playground/wasm/package.json | 1 + playground/worker/package.json | 1 + playground/worker/vite.config-es.js | 4 +-- playground/worker/vite.config-iife.js | 4 +-- .../worker/vite.config-relative-base-iife.js | 4 +-- .../worker/vite.config-relative-base.js | 4 +-- playground/worker/vite.config-sourcemap.js | 4 +-- .../worker/worker-plugin-test-plugin.js | 2 +- 89 files changed, 217 insertions(+), 87 deletions(-) delete mode 100644 playground/hmr/tsconfig.json rename playground/json/__tests__/{ => csr}/json.spec.ts (89%) create mode 100644 playground/json/__tests__/ssr/json.spec.ts create mode 100644 playground/json/__tests__/ssr/serve.ts rename playground/resolve/{config-dep.js => config-dep.cjs} (100%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3128e91c9df364..948041496208bb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -181,6 +181,21 @@ module.exports = defineConfig({ '@typescript-eslint/no-empty-function': 'off', }, }, + { + files: ['playground/**'], + excludedFiles: [ + 'playground/ssr-resolve/**', + 'playground/**/*{commonjs,cjs}*/**', + 'playground/**/*{commonjs,cjs}*', + 'playground/**/*dep*/**', + 'playground/resolve/browser-module-field2/index.web.js', + 'playground/resolve/browser-field/**', + 'playground/tailwind/**', // blocked by https://github.com/postcss/postcss-load-config/issues/239 + ], + rules: { + 'import/no-commonjs': 'error', + }, + }, { files: [ 'playground/tsconfig-json/**', diff --git a/playground/alias/package.json b/playground/alias/package.json index 60c9a67218b86a..78995fa19e045c 100644 --- a/playground/alias/package.json +++ b/playground/alias/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-alias", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/alias/vite.config.js b/playground/alias/vite.config.js index c2b2e7e2e923e0..1312b295b985dd 100644 --- a/playground/alias/vite.config.js +++ b/playground/alias/vite.config.js @@ -1,6 +1,9 @@ import path from 'node:path' +import module from 'node:module' import { defineConfig } from 'vite' +const require = module.createRequire(import.meta.url) + export default defineConfig({ resolve: { alias: [ diff --git a/playground/assets-sanitize/package.json b/playground/assets-sanitize/package.json index 5deedbfaf97f38..1a110936d06db9 100644 --- a/playground/assets-sanitize/package.json +++ b/playground/assets-sanitize/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-assets-sanitize", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/assets/package.json b/playground/assets/package.json index 47e127261142e7..eeec51861fe068 100644 --- a/playground/assets/package.json +++ b/playground/assets/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-assets", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "debug": "node --inspect-brk ../../packages/vite/bin/vite", "dev": "vite", diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index d2d7ac79804c41..12b1aa1de18298 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-backend-integration", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/backend-integration/postcss.config.js b/playground/backend-integration/postcss.config.js index f2f538422a839e..431c1ca465d257 100644 --- a/playground/backend-integration/postcss.config.js +++ b/playground/backend-integration/postcss.config.js @@ -1,5 +1,10 @@ -// postcss.config.js -module.exports = { +import { fileURLToPath } from 'node:url' +import { dirname } from 'node:path' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +export default { plugins: { tailwindcss: { config: __dirname + '/tailwind.config.js' }, }, diff --git a/playground/backend-integration/tailwind.config.js b/playground/backend-integration/tailwind.config.js index a91db5247f6553..bf91cec6521e40 100644 --- a/playground/backend-integration/tailwind.config.js +++ b/playground/backend-integration/tailwind.config.js @@ -1,4 +1,6 @@ -module.exports = { +/** @type {import('tailwindcss').Config} */ + +export default { content: [__dirname + '/frontend/**/*.{css,html,ts,js}'], theme: { extend: {}, diff --git a/playground/build-old/package.json b/playground/build-old/package.json index 9766699a41d435..695d5e6f28fbc7 100644 --- a/playground/build-old/package.json +++ b/playground/build-old/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-build-old", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/cli/package.json b/playground/cli/package.json index 39b7efc3b24304..09b97d52574733 100644 --- a/playground/cli/package.json +++ b/playground/cli/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-cli", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/config/__tests__/load.spec.ts b/playground/config/__tests__/load.spec.ts index 6236fff91b9272..a95cf592130f0b 100644 --- a/playground/config/__tests__/load.spec.ts +++ b/playground/config/__tests__/load.spec.ts @@ -20,7 +20,7 @@ it('loadConfigFromFile', async () => { 4, ], ], - "moduleCondition": "require condition", + "moduleCondition": "import condition", } `) }) diff --git a/playground/config/packages/entry/package.json b/playground/config/packages/entry/package.json index 287aa6c698618b..bb0e07d0af7389 100644 --- a/playground/config/packages/entry/package.json +++ b/playground/config/packages/entry/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-entry", + "type": "module", "dependencies": { "@vite/test-config-plugin-module-condition": "link:../plugin-module-condition" } diff --git a/playground/config/packages/plugin-module-condition/package.json b/playground/config/packages/plugin-module-condition/package.json index 38df99751d9e3e..623a54914737cf 100644 --- a/playground/config/packages/plugin-module-condition/package.json +++ b/playground/config/packages/plugin-module-condition/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-plugin-module-condition", + "type": "module", "exports": { ".": { "types": "./index.d.ts", diff --git a/playground/config/packages/siblings/foo.ts b/playground/config/packages/siblings/foo.ts index 78a8912131faed..efc3b112053c58 100644 --- a/playground/config/packages/siblings/foo.ts +++ b/playground/config/packages/siblings/foo.ts @@ -1,3 +1,3 @@ -import { partition } from 'lodash' +import lodash from 'lodash' -export const array = partition([1, 2, 3, 4], (n) => n % 2) +export const array = lodash.partition([1, 2, 3, 4], (n) => n % 2) diff --git a/playground/config/packages/siblings/package.json b/playground/config/packages/siblings/package.json index 1d7775558a79ac..b4bcc544931887 100644 --- a/playground/config/packages/siblings/package.json +++ b/playground/config/packages/siblings/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-sibling", + "type": "module", "devDependencies": { "@types/lodash": "^4.14.194", "lodash": "^4.17.21" diff --git a/playground/css-codesplit-cjs/package.json b/playground/css-codesplit-cjs/package.json index 97f1473d267e46..e305007adfcb98 100644 --- a/playground/css-codesplit-cjs/package.json +++ b/playground/css-codesplit-cjs/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-codesplit-cjs", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css-codesplit/package.json b/playground/css-codesplit/package.json index ac3149030dceaf..f7edd868783ebf 100644 --- a/playground/css-codesplit/package.json +++ b/playground/css-codesplit/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-codesplit", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css-dynamic-import/package.json b/playground/css-dynamic-import/package.json index 60b8fa380e2243..2b5339f8c72760 100644 --- a/playground/css-dynamic-import/package.json +++ b/playground/css-dynamic-import/package.json @@ -1,5 +1,6 @@ { "name": "@vitejs/test-css-dynamic-import", "private": true, + "type": "module", "version": "0.0.0" } diff --git a/playground/css-sourcemap/package.json b/playground/css-sourcemap/package.json index 0bb168faa6360f..d1ff56dafa781f 100644 --- a/playground/css-sourcemap/package.json +++ b/playground/css-sourcemap/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-sourcemap", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/package.json b/playground/css/package.json index 43e4f87e12db72..d95ef47367e343 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/blue-app/package.json b/playground/css/postcss-caching/blue-app/package.json index 82ba64fadd44b4..528263c4e60923 100644 --- a/playground/css/postcss-caching/blue-app/package.json +++ b/playground/css/postcss-caching/blue-app/package.json @@ -2,6 +2,7 @@ "name": "blue-app", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/blue-app/postcss.config.js b/playground/css/postcss-caching/blue-app/postcss.config.js index 50764f3ff8f21a..679b801013ef1a 100644 --- a/playground/css/postcss-caching/blue-app/postcss.config.js +++ b/playground/css/postcss-caching/blue-app/postcss.config.js @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [replacePinkWithBlue], } diff --git a/playground/css/postcss-caching/green-app/package.json b/playground/css/postcss-caching/green-app/package.json index 72bd0f45b8865f..110ea74558435d 100644 --- a/playground/css/postcss-caching/green-app/package.json +++ b/playground/css/postcss-caching/green-app/package.json @@ -2,6 +2,7 @@ "name": "green-app", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/green-app/postcss.config.js b/playground/css/postcss-caching/green-app/postcss.config.js index 7d9d8818540e09..c0a74e3676976d 100644 --- a/playground/css/postcss-caching/green-app/postcss.config.js +++ b/playground/css/postcss-caching/green-app/postcss.config.js @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [replacePinkWithGreen], } diff --git a/playground/css/postcss.config.js b/playground/css/postcss.config.js index 955878ac216f53..4d2c144b9fa66c 100644 --- a/playground/css/postcss.config.js +++ b/playground/css/postcss.config.js @@ -1,11 +1,12 @@ -module.exports = { - plugins: [require('postcss-nested'), testDirDep, testSourceInput], -} +import fs from 'node:fs' +import path from 'node:path' +import glob from 'fast-glob' +import { normalizePath } from 'vite' +import postcssNested from 'postcss-nested' -const fs = require('node:fs') -const path = require('node:path') -const glob = require('fast-glob') -const { normalizePath } = require('vite') +export default { + plugins: [postcssNested, testDirDep, testSourceInput], +} /** * A plugin for testing the `dir-dependency` message handling. diff --git a/playground/data-uri/package.json b/playground/data-uri/package.json index c19befed0bca09..4e8b2d699f2ac8 100644 --- a/playground/data-uri/package.json +++ b/playground/data-uri/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-data-uri", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/define/package.json b/playground/define/package.json index 9a144c76a4dfb0..a65b36c1c3df67 100644 --- a/playground/define/package.json +++ b/playground/define/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-define", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/dynamic-import/package.json b/playground/dynamic-import/package.json index 55137ef5fb9375..d3ab6846463268 100644 --- a/playground/dynamic-import/package.json +++ b/playground/dynamic-import/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-dynamic-import", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/dynamic-import/vite.config.js b/playground/dynamic-import/vite.config.js index 15aa703d74530a..dc8ecbd8bbdfe5 100644 --- a/playground/dynamic-import/vite.config.js +++ b/playground/dynamic-import/vite.config.js @@ -1,8 +1,8 @@ import fs from 'node:fs' import path from 'node:path' -import vite from 'vite' +import { defineConfig } from 'vite' -export default vite.defineConfig({ +export default defineConfig({ plugins: [ { name: 'copy', diff --git a/playground/env-nested/package.json b/playground/env-nested/package.json index 545eefb2f690d5..060888e998c98d 100644 --- a/playground/env-nested/package.json +++ b/playground/env-nested/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-env-nested", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/env/package.json b/playground/env/package.json index 969f4061114a9d..a50e47e1c17313 100644 --- a/playground/env/package.json +++ b/playground/env/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-env", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "VITE_INLINE=inline-serve vite", "build": "VITE_INLINE=inline-build vite build", diff --git a/playground/extensions/package.json b/playground/extensions/package.json index 30dde24815a6ce..b11cc4a213e352 100644 --- a/playground/extensions/package.json +++ b/playground/extensions/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-extensions", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/external/package.json b/playground/external/package.json index c27e446e8fbdee..6f5141bb15ae9f 100644 --- a/playground/external/package.json +++ b/playground/external/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-external", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/fs-serve/package.json b/playground/fs-serve/package.json index 15fdfe3294cd83..ceb4552d1c244f 100644 --- a/playground/fs-serve/package.json +++ b/playground/fs-serve/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-fs-serve", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite root", "build": "vite build root", diff --git a/playground/glob-import/package.json b/playground/glob-import/package.json index f3ac7ae9313db5..66d4667336a1a5 100644 --- a/playground/glob-import/package.json +++ b/playground/glob-import/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-import-context", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/hmr/package.json b/playground/hmr/package.json index 8bb1d44d18bbe0..35e0799c262738 100644 --- a/playground/hmr/package.json +++ b/playground/hmr/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-hmr", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json deleted file mode 100644 index ca98b7ce20a3ca..00000000000000 --- a/playground/hmr/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../tsconfig.json", - "include": ["."], - "exclude": ["**/dist/**", "**/__tests__/**"], - "compilerOptions": { - "target": "ES2020", - "module": "ESNext", - "outDir": "dist", - "allowJs": true, - "esModuleInterop": true, - "moduleResolution": "bundler", - "baseUrl": ".", - "jsx": "preserve", - "types": ["vite/client", "node"] - } -} diff --git a/playground/html/package.json b/playground/html/package.json index 9eadef9f1a71a8..6bdb23d06194a4 100644 --- a/playground/html/package.json +++ b/playground/html/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-html", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/import-assertion/package.json b/playground/import-assertion/package.json index 03248a46ef4dd3..04ecce34c1f5ec 100644 --- a/playground/import-assertion/package.json +++ b/playground/import-assertion/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-import-assertion", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/js-sourcemap/package.json b/playground/js-sourcemap/package.json index 4b82881a37e473..6381b13c9b09e9 100644 --- a/playground/js-sourcemap/package.json +++ b/playground/js-sourcemap/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-js-sourcemap", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/json/__tests__/json.spec.ts b/playground/json/__tests__/csr/json.spec.ts similarity index 89% rename from playground/json/__tests__/json.spec.ts rename to playground/json/__tests__/csr/json.spec.ts index 5837a236eee314..cec1fb5f0eb0ba 100644 --- a/playground/json/__tests__/json.spec.ts +++ b/playground/json/__tests__/csr/json.spec.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'node:fs' import { expect, test } from 'vitest' -import testJson from '../test.json' -import hmrJson from '../hmr.json' +import deepJson from 'vue/package.json' +import testJson from '../../test.json' +import hmrJson from '../../hmr.json' import { editFile, isBuild, isServe, page, untilUpdated } from '~utils' -const deepJson = require('vue/package.json') const stringified = JSON.stringify(testJson) const deepStringified = JSON.stringify(deepJson) const hmrStringified = JSON.stringify(hmrJson) @@ -45,7 +45,7 @@ test('?url', async () => { test('?raw', async () => { expect(await page.textContent('.raw')).toBe( - readFileSync(require.resolve('../test.json'), 'utf-8'), + readFileSync(require.resolve('../../test.json'), 'utf-8'), ) }) diff --git a/playground/json/__tests__/ssr/json.spec.ts b/playground/json/__tests__/ssr/json.spec.ts new file mode 100644 index 00000000000000..5efbeac7da12d6 --- /dev/null +++ b/playground/json/__tests__/ssr/json.spec.ts @@ -0,0 +1,20 @@ +import { beforeEach, test } from 'vitest' +import { port } from './serve' +import { page, untilUpdated } from '~utils' + +const url = `http://localhost:${port}` + +beforeEach(async () => { + await page.goto(url) +}) + +test('load json module', async () => { + await untilUpdated( + () => page.textContent('.fetch-json-module pre'), + 'export default JSON.parse("{\\n \\"hello\\": \\"hi\\"\\n}\\n")', + ) +}) + +test('fs json', async () => { + await untilUpdated(() => page.textContent('.fetch-json-fs pre'), '61') +}) diff --git a/playground/json/__tests__/ssr/serve.ts b/playground/json/__tests__/ssr/serve.ts new file mode 100644 index 00000000000000..369d3b3999df28 --- /dev/null +++ b/playground/json/__tests__/ssr/serve.ts @@ -0,0 +1,35 @@ +// this is automatically detected by playground/vitestSetup.ts and will replace +// the default e2e test serve behavior + +import path from 'node:path' +import kill from 'kill-port' +import { ports, rootDir } from '~utils' + +export const port = ports.json + +export async function serve(): Promise<{ close(): Promise }> { + await kill(port) + + const { createServer } = await import(path.resolve(rootDir, 'server.js')) + const { app, vite } = await createServer(rootDir) + + return new Promise((resolve, reject) => { + try { + const server = app.listen(port, () => { + resolve({ + // for test teardown + async close() { + await new Promise((resolve) => { + server.close(resolve) + }) + if (vite) { + await vite.close() + } + }, + }) + }) + } catch (e) { + reject(e) + } + }) +} diff --git a/playground/json/package.json b/playground/json/package.json index 748e23fda44137..1484ada27924e5 100644 --- a/playground/json/package.json +++ b/playground/json/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-json", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", @@ -12,8 +13,8 @@ "debug:ssr": "node --inspect-brk server" }, "devDependencies": { - "express": "^4.18.2", "@vitejs/test-json-module": "file:./json-module", + "express": "^4.18.2", "vue": "^3.2.47" } } diff --git a/playground/json/server.js b/playground/json/server.js index 5a7a989d9c39e3..705fd0efa0aabb 100644 --- a/playground/json/server.js +++ b/playground/json/server.js @@ -1,21 +1,22 @@ // @ts-check -const fs = require('node:fs') -const path = require('node:path') -const express = require('express') +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import express from 'express' +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const isTest = process.env.VITEST -async function createServer( - root = process.cwd(), - isProd = process.env.NODE_ENV === 'production', -) { +export async function createServer(root = process.cwd()) { const resolve = (p) => path.resolve(__dirname, p) const app = express() /** * @type {import('vite').ViteDevServer} */ - const vite = await require('vite').createServer({ + const vite = await ( + await import('vite') + ).createServer({ root, logLevel: isTest ? 'error' : 'info', server: { @@ -50,13 +51,16 @@ async function createServer( if (url === '/json-fs') { console.time('transform module') - const source = fs.readFileSync('./test.json', { encoding: 'utf-8' }) + const source = fs.readFileSync(path.resolve(__dirname, './test.json'), { + encoding: 'utf-8', + }) const json = await vite.ssrTransform( `export default ${source}`, null, './output.json', ) console.timeEnd('transform module') + // @ts-expect-error ignore in test res.status(200).end(String(json.code.length)) return } @@ -83,6 +87,3 @@ if (!isTest) { }), ) } - -// for test use -exports.createServer = createServer diff --git a/playground/legacy/__tests__/client-and-ssr/serve.ts b/playground/legacy/__tests__/client-and-ssr/serve.ts index 3dc22f7adc0f45..46a075549db53a 100644 --- a/playground/legacy/__tests__/client-and-ssr/serve.ts +++ b/playground/legacy/__tests__/client-and-ssr/serve.ts @@ -34,7 +34,7 @@ export async function serve(): Promise<{ close(): Promise }> { app.use('/', async (_req, res) => { const { render } = await import( - path.resolve(rootDir, './dist/server/entry-server-sequential.mjs') + path.resolve(rootDir, './dist/server/entry-server-sequential.js') ) const html = await render() res.status(200).set({ 'Content-Type': 'text/html' }).end(html) diff --git a/playground/legacy/__tests__/ssr/serve.ts b/playground/legacy/__tests__/ssr/serve.ts index 69ff2ec940b825..2b20dfc8455d69 100644 --- a/playground/legacy/__tests__/ssr/serve.ts +++ b/playground/legacy/__tests__/ssr/serve.ts @@ -22,7 +22,7 @@ export async function serve(): Promise<{ close(): Promise }> { app.use('/', async (_req, res) => { const { render } = await import( - path.resolve(rootDir, './dist/server/entry-server.mjs') + path.resolve(rootDir, './dist/server/entry-server.js') ) const html = await render() res.status(200).set({ 'Content-Type': 'text/html' }).end(html) diff --git a/playground/legacy/package.json b/playground/legacy/package.json index b47df1430d6cdc..897d9c94ef819d 100644 --- a/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-legacy", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build --debug legacy", diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index ce309a2285fe98..d4ced107fdea7a 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -15,8 +15,10 @@ describe.runIf(isBuild)('build', () => { test('umd', async () => { expect(await page.textContent('.umd')).toBe('It works') - const code = readFile('dist/my-lib-custom-filename.umd.js') - const noMinifyCode = readFile('dist/nominify/my-lib-custom-filename.umd.js') + const code = readFile('dist/my-lib-custom-filename.umd.cjs') + const noMinifyCode = readFile( + 'dist/nominify/my-lib-custom-filename.umd.cjs', + ) // esbuild helpers are injected inside of the UMD wrapper expect(code).toMatch(/^\(function\(/) expect(noMinifyCode).toMatch( @@ -46,7 +48,7 @@ describe.runIf(isBuild)('build', () => { expect(code).not.toMatch('__vitePreload') // Test that library chunks are hashed - expect(code).toMatch(/await import\("\.\/message-[a-z\d]{8}.mjs"\)/) + expect(code).toMatch(/await import\("\.\/message-[a-z\d]{8}.js"\)/) }) test('@import hoist', async () => { @@ -57,9 +59,9 @@ describe.runIf(isBuild)('build', () => { }) test('preserve process.env', () => { - const es = readFile('dist/my-lib-custom-filename.mjs') + const es = readFile('dist/my-lib-custom-filename.js') const iife = readFile('dist/my-lib-custom-filename.iife.js') - const umd = readFile('dist/my-lib-custom-filename.umd.js') + const umd = readFile('dist/my-lib-custom-filename.umd.cjs') expect(es).toMatch('process.env.NODE_ENV') expect(iife).toMatch('process.env.NODE_ENV') expect(umd).toMatch('process.env.NODE_ENV') diff --git a/playground/lib/index.dist.html b/playground/lib/index.dist.html index b719268ded6365..e7fb284811876a 100644 --- a/playground/lib/index.dist.html +++ b/playground/lib/index.dist.html @@ -14,7 +14,7 @@ @@ -25,7 +25,7 @@ message('.dynamic-import-message') - + From a460a2b3ef428986ed1e04a63f558331a7fdc94f Mon Sep 17 00:00:00 2001 From: patak Date: Fri, 26 May 2023 12:23:33 +0200 Subject: [PATCH 49/75] release: v4.3.9 --- packages/vite/CHANGELOG.md | 15 +++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index b468dcdaea91df..fd65b9403420ca 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,18 @@ +## 4.3.9 (2023-05-26) + +* fix: fs.deny with leading double slash (#13348) ([813ddd6](https://github.com/vitejs/vite/commit/813ddd6)), closes [#13348](https://github.com/vitejs/vite/issues/13348) +* fix: optimizeDeps during build and external ids (#13274) ([e3db771](https://github.com/vitejs/vite/commit/e3db771)), closes [#13274](https://github.com/vitejs/vite/issues/13274) +* fix(css): return deps if have no postcss plugins (#13344) ([28923fb](https://github.com/vitejs/vite/commit/28923fb)), closes [#13344](https://github.com/vitejs/vite/issues/13344) +* fix(legacy): style insert order (#13266) ([e444375](https://github.com/vitejs/vite/commit/e444375)), closes [#13266](https://github.com/vitejs/vite/issues/13266) +* chore: revert prev release commit ([2a30a07](https://github.com/vitejs/vite/commit/2a30a07)) +* release: v4.3.9 ([5c9abf7](https://github.com/vitejs/vite/commit/5c9abf7)) +* docs: optimizeDeps.needsInterop (#13323) ([b34e79c](https://github.com/vitejs/vite/commit/b34e79c)), closes [#13323](https://github.com/vitejs/vite/issues/13323) +* test: respect commonjs options in playgrounds (#13273) ([19e8c68](https://github.com/vitejs/vite/commit/19e8c68)), closes [#13273](https://github.com/vitejs/vite/issues/13273) +* refactor: simplify SSR options' if statement (#13254) ([8013a66](https://github.com/vitejs/vite/commit/8013a66)), closes [#13254](https://github.com/vitejs/vite/issues/13254) +* perf(ssr): calculate stacktrace offset lazily (#13256) ([906c4c1](https://github.com/vitejs/vite/commit/906c4c1)), closes [#13256](https://github.com/vitejs/vite/issues/13256) + + + ## 4.3.8 (2023-05-18) * fix: avoid outdated module to crash in importAnalysis after restart (#13231) ([3609e79](https://github.com/vitejs/vite/commit/3609e79)), closes [#13231](https://github.com/vitejs/vite/issues/13231) diff --git a/packages/vite/package.json b/packages/vite/package.json index 13356c846cae99..0220c4174cb838 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "4.3.8", + "version": "4.3.9", "type": "module", "license": "MIT", "author": "Evan You", From d9702c40e74720601f5ea51bd2fbd6048ecf11ad Mon Sep 17 00:00:00 2001 From: Wermeille Bastien Date: Sat, 27 May 2023 11:03:21 +0200 Subject: [PATCH 50/75] docs: update root documentation to include vite config file location (#13345) Co-authored-by: patak --- docs/guide/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/guide/index.md b/docs/guide/index.md index 3ae2c5a0d27e3b..118c53a2f38515 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -110,6 +110,7 @@ Vite also supports [multi-page apps](./build#multi-page-app) with multiple `.htm #### Specifying Alternative Root Running `vite` starts the dev server using the current working directory as root. You can specify an alternative root with `vite serve some/sub/dir`. +Note that Vite will also resolve [its config file (i.e. `vite.config.js`)](/config/#configuring-vite) inside the project root, so you'll need to move it if the root is changed. ## Command Line Interface From 5c3fa057f10b1adea4e28f58f69bf6b636eac4aa Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 29 May 2023 11:27:55 +0200 Subject: [PATCH 51/75] release: create-vite@4.3.2 --- packages/create-vite/CHANGELOG.md | 8 ++++++++ packages/create-vite/package.json | 2 +- packages/create-vite/template-lit-ts/package.json | 2 +- packages/create-vite/template-lit/package.json | 2 +- packages/create-vite/template-preact-ts/package.json | 2 +- packages/create-vite/template-preact/package.json | 2 +- packages/create-vite/template-react-ts/package.json | 2 +- packages/create-vite/template-react/package.json | 2 +- packages/create-vite/template-svelte-ts/package.json | 2 +- packages/create-vite/template-svelte/package.json | 2 +- packages/create-vite/template-vanilla-ts/package.json | 2 +- packages/create-vite/template-vanilla/package.json | 2 +- packages/create-vite/template-vue-ts/package.json | 2 +- packages/create-vite/template-vue/package.json | 2 +- 14 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md index 0b0e445752db88..d50842b51478f7 100644 --- a/packages/create-vite/CHANGELOG.md +++ b/packages/create-vite/CHANGELOG.md @@ -1,3 +1,11 @@ +## 4.3.2 (2023-05-29) + +* fix: upgrade svelte-check preventing unmet peer deps errors (#13103) ([c63ba3f](https://github.com/vitejs/vite/commit/c63ba3f)), closes [#13103](https://github.com/vitejs/vite/issues/13103) +* fix(create-vite): use `"target": "ES2020"` in React template (#13147) ([23096b1](https://github.com/vitejs/vite/commit/23096b1)), closes [#13147](https://github.com/vitejs/vite/issues/13147) +* chore(deps): update all non-major dependencies (#12805) ([5731ac9](https://github.com/vitejs/vite/commit/5731ac9)), closes [#12805](https://github.com/vitejs/vite/issues/12805) + + + ## 4.3.1 (2023-04-25) * chore(create-vite): bump vue-tsc (#12952) ([30fd101](https://github.com/vitejs/vite/commit/30fd101)), closes [#12952](https://github.com/vitejs/vite/issues/12952) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 23cd7a7e57480f..591d731da7dc7f 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -1,6 +1,6 @@ { "name": "create-vite", - "version": "4.3.1", + "version": "4.3.2", "type": "module", "license": "MIT", "author": "Evan You", diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json index 943bbcb13d482a..cd344421463331 100644 --- a/packages/create-vite/template-lit-ts/package.json +++ b/packages/create-vite/template-lit-ts/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json index be2ce45aa302a2..0d889824581633 100644 --- a/packages/create-vite/template-lit/package.json +++ b/packages/create-vite/template-lit/package.json @@ -12,6 +12,6 @@ "lit": "^2.7.2" }, "devDependencies": { - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json index 7a7eef5bacdee6..83ac2f2dab9dbe 100644 --- a/packages/create-vite/template-preact-ts/package.json +++ b/packages/create-vite/template-preact-ts/package.json @@ -14,6 +14,6 @@ "devDependencies": { "@preact/preset-vite": "^2.5.0", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json index 6a116ff5e2ccd9..b1ee76ee5c7eb9 100644 --- a/packages/create-vite/template-preact/package.json +++ b/packages/create-vite/template-preact/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.5.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 63bd22951713e5..b40dedc9d50f66 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -23,6 +23,6 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 181f6b2d5befa4..902650e99682a2 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -21,6 +21,6 @@ "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json index 3e613d9fc7b00d..5dc5b424573708 100644 --- a/packages/create-vite/template-svelte-ts/package.json +++ b/packages/create-vite/template-svelte-ts/package.json @@ -16,6 +16,6 @@ "svelte-check": "^3.3.1", "tslib": "^2.5.0", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-svelte/package.json b/packages/create-vite/template-svelte/package.json index 947d254ffea078..47679aad225444 100644 --- a/packages/create-vite/template-svelte/package.json +++ b/packages/create-vite/template-svelte/package.json @@ -11,6 +11,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^2.0.4", "svelte": "^3.58.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json index 7c063e00a3c35a..eaff1bfcee21b3 100644 --- a/packages/create-vite/template-vanilla-ts/package.json +++ b/packages/create-vite/template-vanilla-ts/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json index a7b823bc7e67c5..e8d3427fee3890 100644 --- a/packages/create-vite/template-vanilla/package.json +++ b/packages/create-vite/template-vanilla/package.json @@ -9,6 +9,6 @@ "preview": "vite preview" }, "devDependencies": { - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vue-ts/package.json b/packages/create-vite/template-vue-ts/package.json index 6dfe1065a2b269..d8d8fc3338ada7 100644 --- a/packages/create-vite/template-vue-ts/package.json +++ b/packages/create-vite/template-vue-ts/package.json @@ -14,7 +14,7 @@ "devDependencies": { "@vitejs/plugin-vue": "^4.1.0", "typescript": "^5.0.2", - "vite": "^4.3.2", + "vite": "^4.3.9", "vue-tsc": "^1.4.2" } } diff --git a/packages/create-vite/template-vue/package.json b/packages/create-vite/template-vue/package.json index 4edfd38a30aebc..86630df8abe203 100644 --- a/packages/create-vite/template-vue/package.json +++ b/packages/create-vite/template-vue/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^4.1.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } From d1cb99ef2681577457628de07a6523fe872166a8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 20:23:39 +0200 Subject: [PATCH 52/75] chore(deps): update tj-actions/changed-files action to v36 (#13360) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73c08de2f54f28..04b2c3f1f3fca0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@7ecfc6730dff8072d1cc5215a24cc9478f55264d # v35.8.0 + uses: tj-actions/changed-files@cf4fe8759a45edd76ed6215da3529d2dbd2a3c68 # v36.0.9 with: files: | docs/** From 2497756b2f3dd5ed498e4b8b01958e76be26cc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 1 Jun 2023 00:21:16 +0900 Subject: [PATCH 53/75] docs: cross drive links troubleshooting guide (#13392) --- docs/guide/troubleshooting.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index c9eeab879c5c5a..ad636a2653c8d6 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -154,3 +154,14 @@ If these code are used inside dependencies, you could use [`patch-package`](http ### 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. + +### Cross drive links on Windows + +If there's a cross drive links in your project on Windows, Vite may not work. + +An example of cross drive links are: + +- a virtual drive linked to a folder by `subst` command +- a symlink/junction to a different drive by `mklink` command (e.g. Yarn global cache) + +Related issue: [#10802](https://github.com/vitejs/vite/issues/10802) From aec1c1d6f07b0b7bc983afffb8733aa38b7c8ede Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 31 May 2023 17:22:08 +0200 Subject: [PATCH 54/75] docs: clarify html input entry name ignored for HTML files (#13389) --- docs/guide/build.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guide/build.md b/docs/guide/build.md index 370b1264e68475..7b711fe03a0bea 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -114,6 +114,8 @@ export default defineConfig({ If you specify a different root, remember that `__dirname` will still be the folder of your vite.config.js file when resolving the input paths. Therefore, you will need to add your `root` entry to the arguments for `resolve`. +Note that for HTML files, Vite ignores the name given to the entry in the `rollupOptions.input` object and instead respects the resolved id of the file when generating the HTML asset in the dist folder. This ensures a consistent structure with the way the dev server works. + ## Library Mode When you are developing a browser-oriented library, you are likely spending most of the time on a test/demo page that imports your actual library. With Vite, you can use your `index.html` for that purpose to get the smooth development experience. From 2872d5520a1a088a89effb155edf59d776a3ced3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 1 Jun 2023 00:52:30 +0900 Subject: [PATCH 55/75] docs: accessing the server on WSL2 from your LAN (#13393) --- docs/config/server-options.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/config/server-options.md b/docs/config/server-options.md index ab0f1b261ddb7c..19065294aeab35 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -34,6 +34,13 @@ The second case is when wildcard hosts (e.g. `0.0.0.0`) are used. This is becaus ::: +::: tip Accessing the server on WSL2 from your LAN + +When running Vite on WSL2, it is not sufficient to set `host: true` to access the server from your LAN. +See [the WSL document](https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan) for more details. + +::: + ## server.port - **Type:** `number` From bf0cd25adb3b8bb5d53433ba9323d0a95e9f756a Mon Sep 17 00:00:00 2001 From: KAROTT Date: Thu, 1 Jun 2023 17:46:49 +0800 Subject: [PATCH 56/75] docs(legacy): add test case to ensure correct csp hashes in readme.md (#13384) Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- packages/plugin-legacy/README.md | 2 +- .../plugin-legacy/src/__tests__/readme.spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/plugin-legacy/src/__tests__/readme.spec.ts diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md index 5381633aa9a91f..04abcec6a3a4e5 100644 --- a/packages/plugin-legacy/README.md +++ b/packages/plugin-legacy/README.md @@ -159,7 +159,7 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https - `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=` - `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=` -- `sha256-p7PoC97FO+Lu90RNjGWxhbm13yALSR4xzV8vaDhaQBo=` +- `sha256-4y/gEB2/KIwZFTfNqwXJq4olzvmQ0S214m9jwKgNXoc=` - `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=`