From 8900c1c5a7b0e1882f092b195691709e9b481792 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 3 Aug 2022 12:56:14 +0800 Subject: [PATCH 01/41] test: vue legacy --- playground/vue-legacy/Main.vue | 10 +++++++++ .../vue-legacy/__tests__/vue-legacy.spec.ts | 0 playground/vue-legacy/assets/asset.png | Bin 0 -> 12772 bytes playground/vue-legacy/env.d.ts | 1 + playground/vue-legacy/index.html | 7 ++++++ playground/vue-legacy/package.json | 18 +++++++++++++++ playground/vue-legacy/vite.config.ts | 21 ++++++++++++++++++ pnpm-lock.yaml | 11 +++++++++ 8 files changed, 68 insertions(+) create mode 100644 playground/vue-legacy/Main.vue create mode 100644 playground/vue-legacy/__tests__/vue-legacy.spec.ts create mode 100644 playground/vue-legacy/assets/asset.png create mode 100644 playground/vue-legacy/env.d.ts create mode 100644 playground/vue-legacy/index.html create mode 100644 playground/vue-legacy/package.json create mode 100644 playground/vue-legacy/vite.config.ts diff --git a/playground/vue-legacy/Main.vue b/playground/vue-legacy/Main.vue new file mode 100644 index 00000000000000..f8bd7c75867567 --- /dev/null +++ b/playground/vue-legacy/Main.vue @@ -0,0 +1,10 @@ + + diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/playground/vue-legacy/assets/asset.png b/playground/vue-legacy/assets/asset.png new file mode 100644 index 0000000000000000000000000000000000000000..1b3356a746b8bb5510aaee51f7df5aea4378ee8d GIT binary patch literal 12772 zcmch82T)Ym)-H$&N*olL90vnANET3%3IdXIY@%ek$x$T;2*MyJ*+y~(p$Scr3=&#V zauARp&>%U(zmMb0?|pUet@~cpyH;6pHhZnL_ln2ZQ@20&bcI#; zRb1q(Z0+v)xLIlXsA|D|?BU{;Y%QIg6L0gA+o+ON#9WUkUItw9LoG z@?#6qUW)C{L+PnJV3BinvtkkE73P8S3*2B473UQY7PuiMz|A7aFCfInFT^Jx#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Zj~Sk7+&*1r&sF;0Iu@#A)vr(idnxZ`=5Lk`(OBc6{zU{@~dH>r2pV+-dUp^217t6nVH5`QcetM1u@7n`oi#fYSDd_)Q+*44MFP1fX{69{$*5UvF literal 0 HcmV?d00001 diff --git a/playground/vue-legacy/env.d.ts b/playground/vue-legacy/env.d.ts new file mode 100644 index 00000000000000..31dca6bb40c906 --- /dev/null +++ b/playground/vue-legacy/env.d.ts @@ -0,0 +1 @@ +declare module '*.png' diff --git a/playground/vue-legacy/index.html b/playground/vue-legacy/index.html new file mode 100644 index 00000000000000..57f325518a2c25 --- /dev/null +++ b/playground/vue-legacy/index.html @@ -0,0 +1,7 @@ +

+ diff --git a/playground/vue-legacy/package.json b/playground/vue-legacy/package.json new file mode 100644 index 00000000000000..201a5ae47bb293 --- /dev/null +++ b/playground/vue-legacy/package.json @@ -0,0 +1,18 @@ +{ + "name": "test-vue-legacy", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", + "preview": "vite preview" + }, + "dependencies": { + "vue": "^3.2.37" + }, + "devDependencies": { + "@vitejs/plugin-vue": "workspace:*", + "@vitejs/plugin-legacy": "workspace:*" + } +} diff --git a/playground/vue-legacy/vite.config.ts b/playground/vue-legacy/vite.config.ts new file mode 100644 index 00000000000000..639d34db665c96 --- /dev/null +++ b/playground/vue-legacy/vite.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'vite' +import vuePlugin from '@vitejs/plugin-vue' +import legacyPlugin from '@vitejs/plugin-legacy' + +export default defineConfig({ + base: '', + resolve: { + alias: { + '@': __dirname + } + }, + plugins: [ + vuePlugin(), + legacyPlugin({ + targets: ['defaults', 'not IE 11', 'chrome > 48'] + }) + ], + build: { + minify: false + } +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3b00d19680be01..566f44ca29d956 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1160,6 +1160,17 @@ importers: '@vitejs/plugin-vue': link:../../packages/plugin-vue '@vitejs/plugin-vue-jsx': link:../../packages/plugin-vue-jsx + playground/vue-legacy: + specifiers: + '@vitejs/plugin-legacy': workspace:* + '@vitejs/plugin-vue': workspace:* + vue: ^3.2.37 + dependencies: + vue: 3.2.37 + devDependencies: + '@vitejs/plugin-legacy': link:../../packages/plugin-legacy + '@vitejs/plugin-vue': link:../../packages/plugin-vue + playground/vue-lib: specifiers: '@vitejs/plugin-vue': workspace:* From b9130cc910b794b95a4b5ee545e80b2e219dc266 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 3 Aug 2022 13:28:45 +0800 Subject: [PATCH 02/41] feat: resolveAssetUrlsInCss in legacy mode --- packages/vite/src/node/plugins/css.ts | 3 +-- playground/vue-legacy/Main.vue | 5 ++++- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 6 ++++++ playground/vue-legacy/vite.config.ts | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b2df2df9f7f0a5..6b0485ad8535a4 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -558,8 +558,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } else if (!config.build.ssr) { // legacy build and inline css - // __VITE_ASSET__ and __VITE_PUBLIC_ASSET__ urls are processed by - // the vite:asset plugin, don't call resolveAssetUrlsInCss here + chunkCSS = resolveAssetUrlsInCss(chunkCSS, chunk.name) chunkCSS = await finalizeCss(chunkCSS, true, config) const style = `__vite_style__` diff --git a/playground/vue-legacy/Main.vue b/playground/vue-legacy/Main.vue index f8bd7c75867567..cf5abfcc7735c3 100644 --- a/playground/vue-legacy/Main.vue +++ b/playground/vue-legacy/Main.vue @@ -5,6 +5,9 @@ diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index e69de29bb2d1d6..e3a9bb5ebbf51e 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -0,0 +1,6 @@ +import { getBg, page } from '~utils' + +test('vue legacy assets', async () => { + const el = await page.$('.container') + expect(await getBg(el)).not.toMatch('__VITE_ASSET__') +}) diff --git a/playground/vue-legacy/vite.config.ts b/playground/vue-legacy/vite.config.ts index 639d34db665c96..2d06c9f228cb27 100644 --- a/playground/vue-legacy/vite.config.ts +++ b/playground/vue-legacy/vite.config.ts @@ -10,10 +10,10 @@ export default defineConfig({ } }, plugins: [ - vuePlugin(), legacyPlugin({ targets: ['defaults', 'not IE 11', 'chrome > 48'] - }) + }), + vuePlugin() ], build: { minify: false From 536cd5efeb0809306c1f305ca83e0456ae31e9cb Mon Sep 17 00:00:00 2001 From: yoho Date: Thu, 4 Aug 2022 21:07:12 +0800 Subject: [PATCH 03/41] feat: test hook for legacy --- playground/vue-legacy/vite.config.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/playground/vue-legacy/vite.config.ts b/playground/vue-legacy/vite.config.ts index 2d06c9f228cb27..5bb2f0efa06f53 100644 --- a/playground/vue-legacy/vite.config.ts +++ b/playground/vue-legacy/vite.config.ts @@ -1,3 +1,5 @@ +import path from 'node:path' +import fs from 'node:fs' import { defineConfig } from 'vite' import vuePlugin from '@vitejs/plugin-vue' import legacyPlugin from '@vitejs/plugin-legacy' @@ -17,5 +19,17 @@ export default defineConfig({ ], build: { minify: false + }, + // special test only hook + // for tests, remove ` From d909dee2254a198b59ec99930f60aebded81aa27 Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 6 Aug 2022 01:15:30 +0800 Subject: [PATCH 05/41] fix: test --- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index e3a9bb5ebbf51e..8e82516979cafc 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -1,6 +1,5 @@ -import { getBg, page } from '~utils' +import { untilUpdated } from '~utils' test('vue legacy assets', async () => { - const el = await page.$('.container') - expect(await getBg(el)).not.toMatch('__VITE_ASSET__') + untilUpdated(() => '.container', 'asset') }) From 6e08b1d5428525cae63dcc482c4a61a7f28b02ad Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 6 Aug 2022 16:11:32 +0800 Subject: [PATCH 06/41] feat: ignore entry chunk insert css --- packages/vite/src/node/plugins/css.ts | 5 +++++ playground/vue-legacy/Main.vue | 19 +++++++++++++++++++ playground/vue-legacy/assets/asset2.png | Bin 0 -> 12772 bytes playground/vue-legacy/index.html | 8 ++++---- playground/vue-legacy/inline.css | 3 +++ playground/vue-legacy/module.vue | 9 +++++++++ 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 playground/vue-legacy/assets/asset2.png create mode 100644 playground/vue-legacy/inline.css create mode 100644 playground/vue-legacy/module.vue diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 0c0d2fba999103..1bceaf3ad13306 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -565,6 +565,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } else if (!config.build.ssr) { // legacy build and inline css + // the entry css will be inlined in the html template + // so don't need to generate the css insert script + if (chunk.isEntry) { + return { code } + } chunkCSS = resolveAssetUrlsInCss(chunkCSS, chunk.name, true) chunkCSS = await finalizeCss(chunkCSS, true, config) const style = `__vite_style__` diff --git a/playground/vue-legacy/Main.vue b/playground/vue-legacy/Main.vue index cf5abfcc7735c3..b92cf06d19cce3 100644 --- a/playground/vue-legacy/Main.vue +++ b/playground/vue-legacy/Main.vue @@ -1,6 +1,25 @@ + From c1eb9b0d225e9688558af4a0145960bb93a5accd Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 6 Aug 2022 16:16:58 +0800 Subject: [PATCH 07/41] fix: error --- packages/vite/src/node/plugins/css.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 1bceaf3ad13306..44e39ebf246e4b 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -493,7 +493,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // replace asset url references with resolved url. chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => { - const filename = getAssetFilename(fileHash, config) + postfix + const filename = getAssetFilename(fileHash, config)! + postfix chunk.viteMetadata.importedAssets.add(cleanUrl(filename)) return toOutputFilePathInCss( filename, From a0caa7c6eb011bf286f69d44fa1d986537f31458 Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 6 Aug 2022 20:30:10 +0800 Subject: [PATCH 08/41] chore: update comment --- packages/vite/src/node/plugins/css.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 44e39ebf246e4b..d9f3e27009d1f9 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -563,9 +563,8 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { - // legacy build and inline css - - // the entry css will be inlined in the html template + // legacy build, inline css + // the entry css(style.css) will be inlined in the html template // so don't need to generate the css insert script if (chunk.isEntry) { return { code } From 18bec1bff4eacfc754e6fb4505f95ede044f673f Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 19:52:55 +0800 Subject: [PATCH 09/41] chore: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- playground/vue-legacy/Main.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue-legacy/Main.vue b/playground/vue-legacy/Main.vue index b92cf06d19cce3..f9cb6dff4003e6 100644 --- a/playground/vue-legacy/Main.vue +++ b/playground/vue-legacy/Main.vue @@ -4,7 +4,7 @@ import css from './inline.css?inline' export default defineComponent({ components: { - module: () => import('./module.vue') + module: defineAsyncComponent(() => import('./module.vue')) }, setup() { return { From 0b4c3cc37ddc692cd5b2e129254cb62c477ccff7 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 19:53:15 +0800 Subject: [PATCH 10/41] chore: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- packages/vite/src/node/plugins/css.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index d9f3e27009d1f9..146e74bf0612b2 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -567,7 +567,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // the entry css(style.css) will be inlined in the html template // so don't need to generate the css insert script if (chunk.isEntry) { - return { code } + return null } chunkCSS = resolveAssetUrlsInCss(chunkCSS, chunk.name, true) chunkCSS = await finalizeCss(chunkCSS, true, config) From fb734fa66a910692364ae24e5d39096731af4de8 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 19:53:22 +0800 Subject: [PATCH 11/41] chore: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index 8e82516979cafc..d4fdc264ec102d 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -1,5 +1,5 @@ import { untilUpdated } from '~utils' test('vue legacy assets', async () => { - untilUpdated(() => '.container', 'asset') + untilUpdated(() => getBg('.container'), 'asset', true) }) From 53bfcf6a4489f488cf0046abb4edd0ca345c1a48 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 19:56:26 +0800 Subject: [PATCH 12/41] chore: revert avoid generate the css insert script --- packages/vite/src/node/plugins/css.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 146e74bf0612b2..d3372aad79d357 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -563,12 +563,6 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { - // legacy build, inline css - // the entry css(style.css) will be inlined in the html template - // so don't need to generate the css insert script - if (chunk.isEntry) { - return null - } chunkCSS = resolveAssetUrlsInCss(chunkCSS, chunk.name, true) chunkCSS = await finalizeCss(chunkCSS, true, config) const style = `__vite_style__` From 43c64ae2bf0fe30a076d3ec14c0f21f8a700d07c Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 20:02:24 +0800 Subject: [PATCH 13/41] chore: update --- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index d4fdc264ec102d..2cd146cb5d7172 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -1,4 +1,4 @@ -import { untilUpdated } from '~utils' +import { getBg, untilUpdated } from '~utils' test('vue legacy assets', async () => { untilUpdated(() => getBg('.container'), 'asset', true) From 2d7812af07f872d21e4c4288b1fbdb66795133c7 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 10 Aug 2022 20:10:18 +0800 Subject: [PATCH 14/41] chore: update --- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index 2cd146cb5d7172..5d08a71fd4df3b 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -1,5 +1,5 @@ -import { getBg, untilUpdated } from '~utils' +import { untilUpdated } from '~utils' test('vue legacy assets', async () => { - untilUpdated(() => getBg('.container'), 'asset', true) + untilUpdated(() => '.container', 'asset', true) }) From f684b78c278703b5dc6a60e96a0da156e5a079b8 Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 16 Aug 2022 22:56:24 +0800 Subject: [PATCH 15/41] chore: renderAssetUrl helper --- packages/vite/src/node/plugins/asset.ts | 149 ++++++++++++++---------- packages/vite/src/node/plugins/css.ts | 69 ++++------- 2 files changed, 113 insertions(+), 105 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 719269c5934290..662027248f11a2 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -2,7 +2,12 @@ import path from 'node:path' import { parse as parseUrl } from 'node:url' import fs, { promises as fsp } from 'node:fs' import * as mrmime from 'mrmime' -import type { OutputOptions, PluginContext, PreRenderedAsset } from 'rollup' +import type { + OutputOptions, + PluginContext, + PreRenderedAsset, + RenderedChunk +} from 'rollup' import MagicString from 'magic-string' import { toOutputFilePathInString } from '../build' import type { Plugin } from '../plugin' @@ -36,6 +41,89 @@ export function registerCustomMime(): void { mrmime.mimes['eot'] = 'application/vnd.ms-fontobject' } +export function renderAssetUrl( + ctx: PluginContext, + code: string, + assetFileName: string, + chunk: RenderedChunk, + config: ResolvedConfig, + hostType: 'js' | 'css' | 'html', + toAssetsRelative?: ( + filename: string, + hostType: string + ) => string | { runtime: string }, + toPublicAssetsRelative?: ( + publicUrl: string, + filename: string, + hostType: string + ) => string | { runtime: string } +): MagicString | undefined { + let match: RegExpExecArray | null + let s: MagicString | undefined + + // Urls added with JS using e.g. + // imgElement.src = "__VITE_ASSET__5aa0ddc0__" are using quotes + + // Urls added in CSS that is imported in JS end up like + // var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aa0ddc0__)}\n"; + + // In both cases, the wrapping should already be fine + + while ((match = assetUrlRE.exec(code))) { + s = s || (s = new MagicString(code)) + const [full, hash, postfix = ''] = match + // some internal plugins may still need to emit chunks (e.g. worker) so + // fallback to this.getFileName for that. TODO: remove, not needed + const file = getAssetFilename(hash, config) || ctx.getFileName(hash) + chunk.viteMetadata.importedAssets.add(cleanUrl(file)) + const filename = file + postfix + const replacement = toOutputFilePathInString( + filename, + 'asset', + assetFileName, + hostType, + config, + toAssetsRelative + ) + const replacementString = + typeof replacement === 'string' + ? JSON.stringify(replacement).slice(1, -1) + : `"+${replacement.runtime}+"` + s.overwrite(match.index, match.index + full.length, replacementString, { + contentOnly: true + }) + } + + // Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths + + const publicAssetUrlMap = publicAssetUrlCache.get(config)! + while ((match = publicAssetUrlRE.exec(code))) { + s = s || (s = new MagicString(code)) + const [full, hash] = match + const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) + const replacement = toOutputFilePathInString( + publicUrl, + 'public', + assetFileName, + hostType, + config, + toPublicAssetsRelative + ? (filename, hostType) => + toPublicAssetsRelative(publicUrl, filename, hostType) + : undefined + ) + const replacementString = + typeof replacement === 'string' + ? JSON.stringify(replacement).slice(1, -1) + : `"+${replacement.runtime}+"` + s.overwrite(match.index, match.index + full.length, replacementString, { + contentOnly: true + }) + } + + return s +} + /** * Also supports loading plain strings with import text from './foo.txt?raw' */ @@ -91,64 +179,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { }, renderChunk(code, chunk) { - let match: RegExpExecArray | null - let s: MagicString | undefined - - // Urls added with JS using e.g. - // imgElement.src = "__VITE_ASSET__5aa0ddc0__" are using quotes - - // Urls added in CSS that is imported in JS end up like - // var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aa0ddc0__)}\n"; - - // In both cases, the wrapping should already be fine - - while ((match = assetUrlRE.exec(code))) { - s = s || (s = new MagicString(code)) - const [full, hash, postfix = ''] = match - // some internal plugins may still need to emit chunks (e.g. worker) so - // fallback to this.getFileName for that. TODO: remove, not needed - const file = getAssetFilename(hash, config) || this.getFileName(hash) - chunk.viteMetadata.importedAssets.add(cleanUrl(file)) - const filename = file + postfix - const replacement = toOutputFilePathInString( - filename, - 'asset', - chunk.fileName, - 'js', - config - ) - const replacementString = - typeof replacement === 'string' - ? JSON.stringify(replacement).slice(1, -1) - : `"+${replacement.runtime}+"` - s.overwrite(match.index, match.index + full.length, replacementString, { - contentOnly: true - }) - } - - // Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths - - const publicAssetUrlMap = publicAssetUrlCache.get(config)! - while ((match = publicAssetUrlRE.exec(code))) { - s = s || (s = new MagicString(code)) - const [full, hash] = match - const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) - const replacement = toOutputFilePathInString( - publicUrl, - 'public', - chunk.fileName, - 'js', - config - ) - const replacementString = - typeof replacement === 'string' - ? JSON.stringify(replacement).slice(1, -1) - : `"+${replacement.runtime}+"` - s.overwrite(match.index, match.index + full.length, replacementString, { - contentOnly: true - }) - } - + const s = renderAssetUrl(this, code, chunk.fileName, chunk, config, 'js') if (s) { return { code: s.toString(), diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index d3372aad79d357..8b260952719efa 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -25,7 +25,6 @@ import type { RawSourceMap } from '@ampproject/remapping' import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' import type { ModuleNode } from '../server/moduleGraph' import type { ResolveFn, ViteDevServer } from '../' -import { toOutputFilePathInCss } from '../build' import { CLIENT_PUBLIC_PATH, SPECIAL_QUERY_RE } from '../constants' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' @@ -48,13 +47,10 @@ import type { Logger } from '../logger' import { addToHTMLProxyTransformResult } from './html' import { assetFileNamesToFileName, - assetUrlRE, checkPublicFile, fileToUrl, - getAssetFilename, - publicAssetUrlCache, - publicAssetUrlRE, publicFileToBuiltUrl, + renderAssetUrl, resolveAssetFileNames } from './asset' import type { ESBuildOptions } from './esbuild' @@ -462,25 +458,20 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { if (!chunkCSS) { return null } - const cssEntryFiles = cssEntryFilesCache.get(config)! - const publicAssetUrlMap = publicAssetUrlCache.get(config)! // resolve asset URL placeholders to their built file URLs - function resolveAssetUrlsInCss( + const resolveAssetUrlsInCss = ( chunkCSS: string, cssAssetName: string, relativeFromPage: boolean = false - ) { - const encodedPublicUrls = encodePublicUrlsInCSS(config) - + ): string => { const relative = config.base === './' || config.base === '' - const cssAssetDirname = - encodedPublicUrls || relative - ? getCssAssetDirname(cssAssetName) - : undefined + const cssAssetDirname = relative + ? getCssAssetDirname(cssAssetName) + : undefined - const toRelative = (filename: string, importer: string) => { + const toRelative = (filename: string) => { // relative base + extracted CSS const relativePath = path.posix.relative(cssAssetDirname!, filename) const resolvedRelativePath = relativePath.startsWith('.') @@ -491,38 +482,24 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { : resolvedRelativePath } - // replace asset url references with resolved url. - chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => { - const filename = getAssetFilename(fileHash, config)! + postfix - chunk.viteMetadata.importedAssets.add(cleanUrl(filename)) - return toOutputFilePathInCss( - filename, - 'asset', + // resolve public URL from CSS paths + const relativePathToPublicFromCSS = path.posix.relative( + cssAssetDirname!, + '' + ) + + return ( + renderAssetUrl( + this, + chunkCSS, cssAssetName, - 'css', + chunk, config, - toRelative - ) - }) - // resolve public URL from CSS paths - if (encodedPublicUrls) { - const relativePathToPublicFromCSS = path.posix.relative( - cssAssetDirname!, - '' - ) - chunkCSS = chunkCSS.replace(publicAssetUrlRE, (_, hash) => { - const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) - return toOutputFilePathInCss( - publicUrl, - 'public', - cssAssetName, - 'css', - config, - () => `${relativePathToPublicFromCSS}/${publicUrl}` - ) - }) - } - return chunkCSS + 'css', + toRelative, + (publicUrl) => `${relativePathToPublicFromCSS}/${publicUrl}` + )?.toString() || chunkCSS + ) } function ensureFileExt(name: string, ext: string) { From b6083fb834c208fc2ee2f6d345809b352d38d586 Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 16 Aug 2022 22:58:12 +0800 Subject: [PATCH 16/41] chore: update --- packages/vite/src/node/plugins/asset.ts | 6 +++--- packages/vite/src/node/plugins/css.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 662027248f11a2..197ad20a9cb356 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -43,10 +43,10 @@ export function registerCustomMime(): void { export function renderAssetUrl( ctx: PluginContext, + config: ResolvedConfig, + chunk: RenderedChunk, code: string, assetFileName: string, - chunk: RenderedChunk, - config: ResolvedConfig, hostType: 'js' | 'css' | 'html', toAssetsRelative?: ( filename: string, @@ -179,7 +179,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { }, renderChunk(code, chunk) { - const s = renderAssetUrl(this, code, chunk.fileName, chunk, config, 'js') + const s = renderAssetUrl(this, config, chunk, code, chunk.fileName, 'js') if (s) { return { code: s.toString(), diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 8b260952719efa..721d43defec2a2 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -491,10 +491,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return ( renderAssetUrl( this, + config, + chunk, chunkCSS, cssAssetName, - chunk, - config, 'css', toRelative, (publicUrl) => `${relativePathToPublicFromCSS}/${publicUrl}` From 2fd5069668f026c957c3d59e5a12734d9523dcbf Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 16 Aug 2022 23:01:57 +0800 Subject: [PATCH 17/41] fix: cssAssetDirname --- packages/vite/src/node/plugins/css.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 721d43defec2a2..d585fd6bd85e30 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -467,9 +467,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { relativeFromPage: boolean = false ): string => { const relative = config.base === './' || config.base === '' - const cssAssetDirname = relative - ? getCssAssetDirname(cssAssetName) - : undefined + const encodedPublicUrls = encodePublicUrlsInCSS(config) + const cssAssetDirname = + encodedPublicUrls || relative + ? getCssAssetDirname(cssAssetName) + : undefined const toRelative = (filename: string) => { // relative base + extracted CSS From 46d57b01d91b424f1b0cee59c80f889909396717 Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 16 Aug 2022 23:33:04 +0800 Subject: [PATCH 18/41] feat: opts --- packages/vite/src/node/plugins/asset.ts | 16 ++++++++++++++-- packages/vite/src/node/plugins/css.ts | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 656e5a7e27cc1d..2c3c0f9f5c2282 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -3,6 +3,7 @@ import { parse as parseUrl } from 'node:url' import fs, { promises as fsp } from 'node:fs' import * as mrmime from 'mrmime' import type { + NormalizedOutputOptions, OutputOptions, PluginContext, PreRenderedAsset, @@ -45,6 +46,7 @@ export function renderAssetUrl( ctx: PluginContext, config: ResolvedConfig, chunk: RenderedChunk, + opts: NormalizedOutputOptions, code: string, assetFileName: string, hostType: 'js' | 'css' | 'html', @@ -83,6 +85,7 @@ export function renderAssetUrl( assetFileName, hostType, config, + opts.format, toAssetsRelative ) const replacementString = @@ -107,6 +110,7 @@ export function renderAssetUrl( assetFileName, hostType, config, + opts.format, toPublicAssetsRelative ? (filename, hostType) => toPublicAssetsRelative(publicUrl, filename, hostType) @@ -178,8 +182,16 @@ export function assetPlugin(config: ResolvedConfig): Plugin { return `export default ${JSON.stringify(url)}` }, - renderChunk(code, chunk) { - const s = renderAssetUrl(this, config, chunk, code, chunk.fileName, 'js') + renderChunk(code, chunk, opts) { + const s = renderAssetUrl( + this, + config, + chunk, + opts, + code, + chunk.fileName, + 'js' + ) if (s) { return { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index d585fd6bd85e30..958f97fd76cc61 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -495,6 +495,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { this, config, chunk, + opts, chunkCSS, cssAssetName, 'css', From 1a50884d521fff4dea168712fcde84504599f11c Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 16 Aug 2022 23:39:25 +0800 Subject: [PATCH 19/41] fix: types --- playground/vue-legacy/__tests__/vue-legacy.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/playground/vue-legacy/__tests__/vue-legacy.spec.ts b/playground/vue-legacy/__tests__/vue-legacy.spec.ts index 5d08a71fd4df3b..c5c42960b70b29 100644 --- a/playground/vue-legacy/__tests__/vue-legacy.spec.ts +++ b/playground/vue-legacy/__tests__/vue-legacy.spec.ts @@ -1,3 +1,4 @@ +import { test } from 'vitest' import { untilUpdated } from '~utils' test('vue legacy assets', async () => { From ecd950b82b5aea8675b1935be34b065c4776d0f5 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 08:48:26 +0800 Subject: [PATCH 20/41] chore: don't modify resolveAssetUrlsInCss --- packages/vite/src/node/plugins/asset.ts | 38 +++---------- packages/vite/src/node/plugins/css.ts | 75 +++++++++++++++++-------- 2 files changed, 60 insertions(+), 53 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 2c3c0f9f5c2282..8fd8b02d159d3b 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -49,16 +49,7 @@ export function renderAssetUrl( opts: NormalizedOutputOptions, code: string, assetFileName: string, - hostType: 'js' | 'css' | 'html', - toAssetsRelative?: ( - filename: string, - hostType: string - ) => string | { runtime: string }, - toPublicAssetsRelative?: ( - publicUrl: string, - filename: string, - hostType: string - ) => string | { runtime: string } + mark: '"' | "'" | '`' = '"' ): MagicString | undefined { let match: RegExpExecArray | null let s: MagicString | undefined @@ -83,15 +74,14 @@ export function renderAssetUrl( filename, 'asset', assetFileName, - hostType, + 'js', config, - opts.format, - toAssetsRelative + opts.format ) const replacementString = typeof replacement === 'string' ? JSON.stringify(replacement).slice(1, -1) - : `"+${replacement.runtime}+"` + : `${mark}+${replacement.runtime}+${mark}` s.overwrite(match.index, match.index + full.length, replacementString, { contentOnly: true }) @@ -108,18 +98,14 @@ export function renderAssetUrl( publicUrl, 'public', assetFileName, - hostType, + 'js', config, - opts.format, - toPublicAssetsRelative - ? (filename, hostType) => - toPublicAssetsRelative(publicUrl, filename, hostType) - : undefined + opts.format ) const replacementString = typeof replacement === 'string' ? JSON.stringify(replacement).slice(1, -1) - : `"+${replacement.runtime}+"` + : `${mark}+${replacement.runtime}+${mark}` s.overwrite(match.index, match.index + full.length, replacementString, { contentOnly: true }) @@ -183,15 +169,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { }, renderChunk(code, chunk, opts) { - const s = renderAssetUrl( - this, - config, - chunk, - opts, - code, - chunk.fileName, - 'js' - ) + const s = renderAssetUrl(this, config, chunk, opts, code, chunk.fileName) if (s) { return { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 958f97fd76cc61..6945fbc1147a08 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -25,6 +25,7 @@ import type { RawSourceMap } from '@ampproject/remapping' import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' import type { ModuleNode } from '../server/moduleGraph' import type { ResolveFn, ViteDevServer } from '../' +import { toOutputFilePathInCss } from '../build' import { CLIENT_PUBLIC_PATH, SPECIAL_QUERY_RE } from '../constants' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' @@ -47,8 +48,12 @@ import type { Logger } from '../logger' import { addToHTMLProxyTransformResult } from './html' import { assetFileNamesToFileName, + assetUrlRE, checkPublicFile, fileToUrl, + getAssetFilename, + publicAssetUrlCache, + publicAssetUrlRE, publicFileToBuiltUrl, renderAssetUrl, resolveAssetFileNames @@ -458,22 +463,25 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { if (!chunkCSS) { return null } + const cssEntryFiles = cssEntryFilesCache.get(config)! + const publicAssetUrlMap = publicAssetUrlCache.get(config)! // resolve asset URL placeholders to their built file URLs - const resolveAssetUrlsInCss = ( + function resolveAssetUrlsInCss( chunkCSS: string, cssAssetName: string, relativeFromPage: boolean = false - ): string => { - const relative = config.base === './' || config.base === '' + ) { const encodedPublicUrls = encodePublicUrlsInCSS(config) + + const relative = config.base === './' || config.base === '' const cssAssetDirname = encodedPublicUrls || relative ? getCssAssetDirname(cssAssetName) : undefined - const toRelative = (filename: string) => { + const toRelative = (filename: string, importer: string) => { // relative base + extracted CSS const relativePath = path.posix.relative(cssAssetDirname!, filename) const resolvedRelativePath = relativePath.startsWith('.') @@ -484,25 +492,38 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { : resolvedRelativePath } - // resolve public URL from CSS paths - const relativePathToPublicFromCSS = path.posix.relative( - cssAssetDirname!, - '' - ) - - return ( - renderAssetUrl( - this, - config, - chunk, - opts, - chunkCSS, + // replace asset url references with resolved url. + chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => { + const filename = getAssetFilename(fileHash, config)! + postfix + chunk.viteMetadata.importedAssets.add(cleanUrl(filename)) + return toOutputFilePathInCss( + filename, + 'asset', cssAssetName, 'css', - toRelative, - (publicUrl) => `${relativePathToPublicFromCSS}/${publicUrl}` - )?.toString() || chunkCSS - ) + config, + toRelative + ) + }) + // resolve public URL from CSS paths + if (encodedPublicUrls) { + const relativePathToPublicFromCSS = path.posix.relative( + cssAssetDirname!, + '' + ) + chunkCSS = chunkCSS.replace(publicAssetUrlRE, (_, hash) => { + const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) + return toOutputFilePathInCss( + publicUrl, + 'public', + cssAssetName, + 'css', + config, + () => `${relativePathToPublicFromCSS}/${publicUrl}` + ) + }) + } + return chunkCSS } function ensureFileExt(name: string, ext: string) { @@ -543,12 +564,20 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { - chunkCSS = resolveAssetUrlsInCss(chunkCSS, chunk.name, true) + chunkCSS = + renderAssetUrl( + this, + config, + chunk, + opts, + chunkCSS, + chunk.name, + '`' + )?.toString() || chunkCSS chunkCSS = await finalizeCss(chunkCSS, true, config) const style = `__vite_style__` const injectCode = `var ${style} = document.createElement('style');` + - `var relativeFromPage = (u) => new URL(u, self.location).href;` + `${style}.innerHTML = \`${chunkCSS}\`;` + `document.head.appendChild(${style});` if (config.build.sourcemap) { From 57b3595e2ec10423ed1821bae3785eed42e76c27 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 08:49:12 +0800 Subject: [PATCH 21/41] chore: revert resolveAssetUrlsInCss --- packages/vite/src/node/plugins/css.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 6945fbc1147a08..c5f24fa13f5167 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -468,11 +468,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const publicAssetUrlMap = publicAssetUrlCache.get(config)! // resolve asset URL placeholders to their built file URLs - function resolveAssetUrlsInCss( - chunkCSS: string, - cssAssetName: string, - relativeFromPage: boolean = false - ) { + function resolveAssetUrlsInCss(chunkCSS: string, cssAssetName: string) { const encodedPublicUrls = encodePublicUrlsInCSS(config) const relative = config.base === './' || config.base === '' @@ -484,17 +480,14 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const toRelative = (filename: string, importer: string) => { // relative base + extracted CSS const relativePath = path.posix.relative(cssAssetDirname!, filename) - const resolvedRelativePath = relativePath.startsWith('.') + return relativePath.startsWith('.') ? relativePath : './' + relativePath - return relativeFromPage - ? `\${relativeFromPage('${filename}')}` - : resolvedRelativePath } // replace asset url references with resolved url. chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => { - const filename = getAssetFilename(fileHash, config)! + postfix + const filename = getAssetFilename(fileHash, config) + postfix chunk.viteMetadata.importedAssets.add(cleanUrl(filename)) return toOutputFilePathInCss( filename, From e91fe24afdf97bff7a288129b2046f92a5ca1250 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 08:52:27 +0800 Subject: [PATCH 22/41] chore: update --- packages/vite/src/node/plugins/asset.ts | 9 ++++----- packages/vite/src/node/plugins/css.ts | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 8fd8b02d159d3b..72947d9bf09ade 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -42,13 +42,12 @@ export function registerCustomMime(): void { mrmime.mimes['eot'] = 'application/vnd.ms-fontobject' } -export function renderAssetUrl( +export function renderAssetUrlInJS( ctx: PluginContext, config: ResolvedConfig, chunk: RenderedChunk, opts: NormalizedOutputOptions, code: string, - assetFileName: string, mark: '"' | "'" | '`' = '"' ): MagicString | undefined { let match: RegExpExecArray | null @@ -73,7 +72,7 @@ export function renderAssetUrl( const replacement = toOutputFilePathInString( filename, 'asset', - assetFileName, + chunk.fileName, 'js', config, opts.format @@ -97,7 +96,7 @@ export function renderAssetUrl( const replacement = toOutputFilePathInString( publicUrl, 'public', - assetFileName, + chunk.fileName, 'js', config, opts.format @@ -169,7 +168,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { }, renderChunk(code, chunk, opts) { - const s = renderAssetUrl(this, config, chunk, opts, code, chunk.fileName) + const s = renderAssetUrlInJS(this, config, chunk, opts, code) if (s) { return { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c5f24fa13f5167..484a2d2a480406 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -55,7 +55,7 @@ import { publicAssetUrlCache, publicAssetUrlRE, publicFileToBuiltUrl, - renderAssetUrl, + renderAssetUrlInJS, resolveAssetFileNames } from './asset' import type { ESBuildOptions } from './esbuild' @@ -558,13 +558,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { chunkCSS = - renderAssetUrl( + renderAssetUrlInJS( this, config, chunk, opts, chunkCSS, - chunk.name, '`' )?.toString() || chunkCSS chunkCSS = await finalizeCss(chunkCSS, true, config) From 86af81dd7f73a53a14ad6c1f3973425e12eb16c6 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 17:37:09 +0800 Subject: [PATCH 23/41] chore: update Co-authored-by: patak --- packages/vite/src/node/plugins/css.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 484a2d2a480406..75c88970fe9189 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -557,16 +557,16 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { - chunkCSS = + chunkCSS = await finalizeCss(chunkCSS, true, config) + let cssString = JSON.stringify(chunkCSS) renderAssetUrlInJS( this, config, chunk, opts, - chunkCSS, + cssString, '`' - )?.toString() || chunkCSS - chunkCSS = await finalizeCss(chunkCSS, true, config) + )?.toString() || cssString const style = `__vite_style__` const injectCode = `var ${style} = document.createElement('style');` + From 45dfb2228f26fb283224abd024119ce776fb19fa Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 17:40:34 +0800 Subject: [PATCH 24/41] feat: no wrap --- packages/vite/src/node/plugins/asset.ts | 7 +++---- packages/vite/src/node/plugins/css.ts | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 72947d9bf09ade..016eafbb1aee8e 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -47,8 +47,7 @@ export function renderAssetUrlInJS( config: ResolvedConfig, chunk: RenderedChunk, opts: NormalizedOutputOptions, - code: string, - mark: '"' | "'" | '`' = '"' + code: string ): MagicString | undefined { let match: RegExpExecArray | null let s: MagicString | undefined @@ -80,7 +79,7 @@ export function renderAssetUrlInJS( const replacementString = typeof replacement === 'string' ? JSON.stringify(replacement).slice(1, -1) - : `${mark}+${replacement.runtime}+${mark}` + : `"+${replacement.runtime}+"` s.overwrite(match.index, match.index + full.length, replacementString, { contentOnly: true }) @@ -104,7 +103,7 @@ export function renderAssetUrlInJS( const replacementString = typeof replacement === 'string' ? JSON.stringify(replacement).slice(1, -1) - : `${mark}+${replacement.runtime}+${mark}` + : `"+${replacement.runtime}+"` s.overwrite(match.index, match.index + full.length, replacementString, { contentOnly: true }) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 75c88970fe9189..b34560ca4d0599 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -559,18 +559,18 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } else if (!config.build.ssr) { chunkCSS = await finalizeCss(chunkCSS, true, config) let cssString = JSON.stringify(chunkCSS) + cssString = renderAssetUrlInJS( this, config, chunk, opts, - cssString, - '`' + cssString )?.toString() || cssString const style = `__vite_style__` const injectCode = `var ${style} = document.createElement('style');` + - `${style}.innerHTML = \`${chunkCSS}\`;` + + `${style}.innerHTML = ${cssString};` + `document.head.appendChild(${style});` if (config.build.sourcemap) { const s = new MagicString(code) From 32fbeb3153d677bff6be5c5ca97a14ac91c067e4 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 18:32:58 +0800 Subject: [PATCH 25/41] chore: update --- packages/vite/src/node/plugins/asset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 016eafbb1aee8e..b20d683e7e09ec 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -61,7 +61,7 @@ export function renderAssetUrlInJS( // In both cases, the wrapping should already be fine while ((match = assetUrlRE.exec(code))) { - s = s || (s = new MagicString(code)) + s ||= s = new MagicString(code) const [full, hash, postfix = ''] = match // some internal plugins may still need to emit chunks (e.g. worker) so // fallback to this.getFileName for that. TODO: remove, not needed From b682325c701caf274224e5b595081ca14c895d23 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 19:36:30 +0800 Subject: [PATCH 26/41] chore: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- packages/vite/src/node/plugins/asset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index b20d683e7e09ec..d7fa0e9264e5be 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -89,7 +89,7 @@ export function renderAssetUrlInJS( const publicAssetUrlMap = publicAssetUrlCache.get(config)! while ((match = publicAssetUrlRE.exec(code))) { - s = s || (s = new MagicString(code)) + s ||= new MagicString(code) const [full, hash] = match const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) const replacement = toOutputFilePathInString( From 297b7657cfba214b5563375df63ddc5090e63e86 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 17 Aug 2022 19:36:51 +0800 Subject: [PATCH 27/41] chore: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- playground/vue-legacy/Main.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue-legacy/Main.vue b/playground/vue-legacy/Main.vue index f9cb6dff4003e6..3a063831e29674 100644 --- a/playground/vue-legacy/Main.vue +++ b/playground/vue-legacy/Main.vue @@ -1,5 +1,5 @@