diff --git a/docs/config/index.md b/docs/config/index.md index 77fbeaca515c6e..905ffae7a89cea 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -27,7 +27,8 @@ You can also explicitly specify a config file to use with the `--config` CLI opt vite --config my-config.js ``` -Note that Vite will replace `__filename`, `__dirname`, and `import.meta.url`. Using these as variable names will result in an error: +::: tip NOTE +Vite will replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS** and **TypeScript** config files. Using these as variable names will result in an error: ```js const __filename = "value" @@ -35,6 +36,8 @@ const __filename = "value" const "path/vite.config.js" = "value" ``` +::: + ### Config Intellisense Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints: diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 4d3de16792295e..e692c0ca7e5fe8 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,15 @@ +## 2.9.0-beta.4 (2022-03-19) + +* fix: add version to optimized chunks, fix #7323 (#7350) ([1be1db6](https://github.com/vitejs/vite/commit/1be1db6)), closes [#7323](https://github.com/vitejs/vite/issues/7323) [#7350](https://github.com/vitejs/vite/issues/7350) +* fix: browser cache of newly discovered deps (#7378) ([392a0de](https://github.com/vitejs/vite/commit/392a0de)), closes [#7378](https://github.com/vitejs/vite/issues/7378) +* fix: do not warn (about not being able to bundle non module scripts) when src is an external url (#7 ([0646fe8](https://github.com/vitejs/vite/commit/0646fe8)), closes [#7380](https://github.com/vitejs/vite/issues/7380) +* fix: overwrite deps info browserHash only on commit (#7359) ([1e9615d](https://github.com/vitejs/vite/commit/1e9615d)), closes [#7359](https://github.com/vitejs/vite/issues/7359) +* chore: fix typo in comment (#7370) ([e682863](https://github.com/vitejs/vite/commit/e682863)), closes [#7370](https://github.com/vitejs/vite/issues/7370) +* chore: update es-module-lexer (#7357) ([fde0f3c](https://github.com/vitejs/vite/commit/fde0f3c)), closes [#7357](https://github.com/vitejs/vite/issues/7357) +* chore(deps): update all non-major dependencies (#6905) ([839665c](https://github.com/vitejs/vite/commit/839665c)), closes [#6905](https://github.com/vitejs/vite/issues/6905) + + + ## 2.9.0-beta.3 (2022-03-16) * fix: delayed full page reload (#7347) ([fa0820a](https://github.com/vitejs/vite/commit/fa0820a)), closes [#7347](https://github.com/vitejs/vite/issues/7347) diff --git a/packages/vite/package.json b/packages/vite/package.json index f67263a284dd4b..d6952c40cace43 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.9.0-beta.3", + "version": "2.9.0-beta.4", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 5658841639afbf..0f8b15e7433d02 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -633,10 +633,7 @@ export function getHash(text: string) { return createHash('sha256').update(text).digest('hex').substring(0, 8) } -export function getOptimizedBrowserHash( - hash: string, - deps: Record -) { +function getOptimizedBrowserHash(hash: string, deps: Record) { return getHash(hash + JSON.stringify(deps)) } @@ -858,8 +855,8 @@ export function optimizeDepInfoFromFile( ): OptimizedDepInfo | undefined { return ( findFileInfo(metadata.optimized, file) || - findFileInfo(metadata.chunks, file) || - findFileInfo(metadata.discovered, file) + findFileInfo(metadata.discovered, file) || + findFileInfo(metadata.chunks, file) ) } diff --git a/packages/vite/src/node/optimizer/registerMissing.ts b/packages/vite/src/node/optimizer/registerMissing.ts index 7e17a6ede7bab7..3c11723197c763 100644 --- a/packages/vite/src/node/optimizer/registerMissing.ts +++ b/packages/vite/src/node/optimizer/registerMissing.ts @@ -271,7 +271,7 @@ export function createOptimizedDeps( runOptimizer(ssr) } - const optimizedDepsTimestamp = Date.now() + const discoveredTimestamp = Date.now() function getDiscoveredBrowserHash( hash: string, @@ -282,7 +282,7 @@ export function createOptimizedDeps( hash + JSON.stringify(deps) + JSON.stringify(missing) + - optimizedDepsTimestamp + discoveredTimestamp ) } @@ -301,6 +301,10 @@ export function createOptimizedDeps( if (optimized) { return optimized } + const chunk = metadata.chunks[id] + if (chunk) { + return chunk + } let missing = metadata.discovered[id] if (missing) { // We are already discover this dependency diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index b1509ac2cdecdd..bfa2fe9c897868 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -297,9 +297,11 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { someScriptsAreAsync ||= isAsync someScriptsAreDefer ||= !isAsync } else if (url && !isPublicFile) { - config.logger.warn( - `