From 6da4eb6f5511205f13ce5eb20c0db114d8173ff0 Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 14 Nov 2022 22:03:54 +0100 Subject: [PATCH 1/5] feat: align default chunk and asset file names with rollup --- packages/plugin-legacy/src/index.ts | 2 +- packages/vite/src/node/build.ts | 8 ++--- packages/vite/src/node/plugins/worker.ts | 6 ++-- playground/assets/__tests__/assets.spec.ts | 8 ++--- .../relative-base-assets.spec.ts | 12 +++---- .../runtime-base/runtime-base-assets.spec.ts | 14 ++++---- .../assets/vite.config-relative-base.js | 4 +-- playground/assets/vite.config-runtime-base.js | 4 +-- .../__tests__/backend-integration.spec.ts | 2 +- .../__tests__/css-dynamic-import.spec.ts | 12 +++---- playground/css/__tests__/css.spec.ts | 16 ++++----- playground/css/vite.config-relative-base.js | 4 +-- .../glob-import/__tests__/glob-import.spec.ts | 2 +- playground/legacy/__tests__/legacy.spec.ts | 2 +- .../legacy/vite.config-multiple-output.js | 4 +-- playground/lib/__tests__/lib.spec.ts | 2 +- playground/preload/__tests__/preload.spec.ts | 4 +-- .../resolve-deps/preload-resolve-deps.spec.ts | 4 +-- playground/ssr-vue/__tests__/ssr-vue.spec.ts | 30 ++++++++-------- .../__tests__/ssr-webworker.spec.ts | 2 +- .../__tests__/vue-server-origin.spec.ts | 2 +- playground/vue/__tests__/vue.spec.ts | 4 +-- .../worker/__tests__/es/es-worker.spec.ts | 2 +- .../worker/__tests__/iife/iife-worker.spec.ts | 2 +- .../relative-base-worker.spec.ts | 4 +-- .../sourcemap-hidden-worker.spec.ts | 24 ++++++------- .../sourcemap-inline-worker.spec.ts | 12 +++---- .../sourcemap/sourcemap-worker.spec.ts | 36 +++++++++---------- playground/worker/vite.config-es.js | 6 ++-- playground/worker/vite.config-iife.js | 8 ++--- .../worker/vite.config-relative-base.js | 6 ++-- playground/worker/vite.config-sourcemap.js | 12 +++---- 32 files changed, 127 insertions(+), 133 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index e22898032f854e..b131727849f1f0 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -298,7 +298,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { | string | ((chunkInfo: PreRenderedChunk) => string) | undefined, - defaultFileName = '[name]-legacy.[hash].js' + defaultFileName = '[name]-legacy-[hash].js' ): string | ((chunkInfo: PreRenderedChunk) => string) => { if (!fileNames) { return path.posix.join(config.build.assetsDir, defaultFileName) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 8ebe96ccd41a52..db20ba374bed4c 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -576,13 +576,13 @@ async function doBuild( : libOptions ? ({ name }) => resolveLibFilename(libOptions, format, name, config.root, jsExt) - : path.posix.join(options.assetsDir, `[name].[hash].${jsExt}`), + : path.posix.join(options.assetsDir, `[name]-[hash].${jsExt}`), chunkFileNames: libOptions - ? `[name].[hash].${jsExt}` - : path.posix.join(options.assetsDir, `[name].[hash].${jsExt}`), + ? `[name]-[hash].${jsExt}` + : path.posix.join(options.assetsDir, `[name]-[hash].${jsExt}`), assetFileNames: libOptions ? `[name].[ext]` - : path.posix.join(options.assetsDir, `[name].[hash].[ext]`), + : path.posix.join(options.assetsDir, `[name]-[hash].[ext]`), inlineDynamicImports: output.format === 'umd' || output.format === 'iife' || diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index 02d0dd3d74ece4..9c3dc54654e2dd 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -79,15 +79,15 @@ export async function bundleWorkerEntry( } = await bundle.generate({ entryFileNames: path.posix.join( config.build.assetsDir, - '[name].[hash].js' + '[name]-[hash].js' ), chunkFileNames: path.posix.join( config.build.assetsDir, - '[name].[hash].js' + '[name]-[hash].js' ), assetFileNames: path.posix.join( config.build.assetsDir, - '[name].[hash].[ext]' + '[name]-[hash].[ext]' ), ...workerConfig, format, diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index 3c20dc96246574..e87e084db6aa09 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -19,7 +19,7 @@ import { } from '~utils' const assetMatch = isBuild - ? /\/foo\/assets\/asset\.\w{8}\.png/ + ? /\/foo\/assets\/asset-\w{8}\.png/ : '/foo/nested/asset.png' const iconMatch = `/foo/icon.png` @@ -209,8 +209,8 @@ describe('image', () => { srcset.split(', ').forEach((s) => { expect(s).toMatch( isBuild - ? /\/foo\/assets\/asset\.\w{8}\.png \dx/ - : /\/foo\/nested\/asset\.png \dx/ + ? /\/foo\/assets\/asset-\w{8}\.png \dx/ + : /\/foo\/nested\/asset-png \dx/ ) }) }) @@ -338,7 +338,7 @@ describe.runIf(isBuild)('css and assets in css in build watch', () => { test('css will not be lost and css does not contain undefined', async () => { editFile('index.html', (code) => code.replace('Assets', 'assets'), true) await notifyRebuildComplete(watcher) - const cssFile = findAssetFile(/index\.\w+\.css$/, 'foo') + const cssFile = findAssetFile(/index-\w+\.css$/, 'foo') expect(cssFile).not.toBe('') expect(cssFile).not.toMatch(/undefined/) }) diff --git a/playground/assets/__tests__/relative-base/relative-base-assets.spec.ts b/playground/assets/__tests__/relative-base/relative-base-assets.spec.ts index f62b23a2083204..7163b425ecc585 100644 --- a/playground/assets/__tests__/relative-base/relative-base-assets.spec.ts +++ b/playground/assets/__tests__/relative-base/relative-base-assets.spec.ts @@ -10,7 +10,7 @@ import { } from '~utils' const absoluteAssetMatch = isBuild - ? /http.*\/other-assets\/asset\.\w{8}\.png/ + ? /http.*\/other-assets\/asset-\w{8}\.png/ : '/nested/asset.png' // Asset URLs in CSS are relative to the same dir, the computed @@ -20,7 +20,7 @@ const cssBgAssetMatch = absoluteAssetMatch const iconMatch = `/icon.png` const absoluteIconMatch = isBuild - ? /http.*\/icon\.\w{8}\.png/ + ? /http.*\/icon-\w{8}\.png/ : '/nested/icon.png' const absolutePublicIconMatch = isBuild ? /http.*\/icon\.png/ : '/icon.png' @@ -143,7 +143,7 @@ describe.runIf(isBuild)('index.css URLs', () => { }) test('relative asset URL', () => { - expect(css).toMatch(`./asset.`) + expect(css).toMatch(`./asset-`) }) test('preserve postfix query/hash', () => { @@ -158,7 +158,7 @@ describe('image', () => { srcset.split(', ').forEach((s) => { expect(s).toMatch( isBuild - ? /other-assets\/asset\.\w{8}\.png \dx/ + ? /other-assets\/asset-\w{8}\.png \dx/ : /\.\/nested\/asset\.png \dx/ ) }) @@ -191,14 +191,14 @@ test('?raw import', async () => { test('?url import', async () => { expect(await page.textContent('.url')).toMatch( - isBuild ? /http.*\/other-assets\/foo\.\w{8}\.js/ : `/foo.js` + isBuild ? /http.*\/other-assets\/foo-\w{8}\.js/ : `/foo.js` ) }) test('?url import on css', async () => { const txt = await page.textContent('.url-css') expect(txt).toMatch( - isBuild ? /http.*\/other-assets\/icons\.\w{8}\.css/ : '/css/icons.css' + isBuild ? /http.*\/other-assets\/icons-\w{8}\.css/ : '/css/icons.css' ) }) diff --git a/playground/assets/__tests__/runtime-base/runtime-base-assets.spec.ts b/playground/assets/__tests__/runtime-base/runtime-base-assets.spec.ts index 90cd764cafe209..0606e8bf8dfa88 100644 --- a/playground/assets/__tests__/runtime-base/runtime-base-assets.spec.ts +++ b/playground/assets/__tests__/runtime-base/runtime-base-assets.spec.ts @@ -9,7 +9,7 @@ import { } from '~utils' const absoluteAssetMatch = isBuild - ? /\/other-assets\/asset\.\w{8}\.png/ + ? /\/other-assets\/asset-\w{8}\.png/ : '/nested/asset.png' // Asset URLs in CSS are relative to the same dir, the computed @@ -19,7 +19,7 @@ const cssBgAssetMatch = absoluteAssetMatch const iconMatch = `/icon.png` const absoluteIconMatch = isBuild - ? /\/other-assets\/icon\.\w{8}\.png/ + ? /\/other-assets\/icon-\w{8}\.png/ : '/nested/icon.png' const absolutePublicIconMatch = isBuild ? /\/icon\.png/ : '/icon.png' @@ -137,11 +137,11 @@ describe('css url() references', () => { describe.runIf(isBuild)('index.css URLs', () => { let css: string beforeAll(() => { - css = findAssetFile(/index.*\.css$/, '', 'other-assets') + css = findAssetFile(/index-\w{8}\.css$/, '', 'other-assets') }) test('relative asset URL', () => { - expect(css).toMatch(`./asset.`) + expect(css).toMatch(`./asset-`) }) test('preserve postfix query/hash', () => { @@ -156,7 +156,7 @@ describe('image', () => { srcset.split(', ').forEach((s) => { expect(s).toMatch( isBuild - ? /other-assets\/asset\.\w{8}\.png \dx/ + ? /other-assets\/asset-\w{8}\.png \dx/ : /\.\/nested\/asset\.png \dx/ ) }) @@ -189,14 +189,14 @@ test('?raw import', async () => { test('?url import', async () => { expect(await page.textContent('.url')).toMatch( - isBuild ? /\/other-assets\/foo\.\w{8}\.js/ : `/foo.js` + isBuild ? /\/other-assets\/foo-\w{8}\.js/ : `/foo.js` ) }) test('?url import on css', async () => { const txt = await page.textContent('.url-css') expect(txt).toMatch( - isBuild ? /\/other-assets\/icons\.\w{8}\.css/ : '/css/icons.css' + isBuild ? /\/other-assets\/icons-\w{8}\.css/ : '/css/icons.css' ) }) diff --git a/playground/assets/vite.config-relative-base.js b/playground/assets/vite.config-relative-base.js index ae09766c0768ac..7b54a149bcd987 100644 --- a/playground/assets/vite.config-relative-base.js +++ b/playground/assets/vite.config-relative-base.js @@ -15,8 +15,8 @@ module.exports = { rollupOptions: { output: { entryFileNames: 'entries/[name].js', - chunkFileNames: 'chunks/[name].[hash].js', - assetFileNames: 'other-assets/[name].[hash][extname]' + chunkFileNames: 'chunks/[name]-[hash].js', + assetFileNames: 'other-assets/[name]-[hash][extname]' } } }, diff --git a/playground/assets/vite.config-runtime-base.js b/playground/assets/vite.config-runtime-base.js index 1752e974b8abcd..12d20e7956e131 100644 --- a/playground/assets/vite.config-runtime-base.js +++ b/playground/assets/vite.config-runtime-base.js @@ -22,8 +22,8 @@ module.exports = { rollupOptions: { output: { entryFileNames: 'entries/[name].js', - chunkFileNames: 'chunks/[name].[hash].js', - assetFileNames: 'other-assets/[name].[hash][extname]' + chunkFileNames: 'chunks/[name]-[hash].js', + assetFileNames: 'other-assets/[name]-[hash][extname]' } } }, diff --git a/playground/backend-integration/__tests__/backend-integration.spec.ts b/playground/backend-integration/__tests__/backend-integration.spec.ts index bd3ee1655dd976..d1611d8c8d088c 100644 --- a/playground/backend-integration/__tests__/backend-integration.spec.ts +++ b/playground/backend-integration/__tests__/backend-integration.spec.ts @@ -12,7 +12,7 @@ import { } from '~utils' const outerAssetMatch = isBuild - ? /\/dev\/assets\/logo\.\w{8}\.png/ + ? /\/dev\/assets\/logo-\w{8}\.png/ : /\/dev\/@fs\/.+?\/images\/logo\.png/ test('should have no 404s', () => { diff --git a/playground/css-dynamic-import/__tests__/css-dynamic-import.spec.ts b/playground/css-dynamic-import/__tests__/css-dynamic-import.spec.ts index 1bcdb0a0d99b07..0dbd34742d53df 100644 --- a/playground/css-dynamic-import/__tests__/css-dynamic-import.spec.ts +++ b/playground/css-dynamic-import/__tests__/css-dynamic-import.spec.ts @@ -66,32 +66,32 @@ baseOptions.forEach(({ base, label }) => { expect(await getColor('.css-dynamic-import')).toBe('green') expect(await getLinks()).toEqual([ { - pathname: expect.stringMatching(/^\/assets\/index\..+\.css$/), + pathname: expect.stringMatching(/^\/assets\/index-.+\.css$/), rel: 'stylesheet', as: '' }, { - pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.css$/), + pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.css$/), rel: 'preload', as: 'style' }, { - pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.js$/), + pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.js$/), rel: 'modulepreload', as: 'script' }, { - pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.css$/), + pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.css$/), rel: 'stylesheet', as: '' }, { - pathname: expect.stringMatching(/^\/assets\/static\..+\.js$/), + pathname: expect.stringMatching(/^\/assets\/static-.+\.js$/), rel: 'modulepreload', as: 'script' }, { - pathname: expect.stringMatching(/^\/assets\/index\..+\.js$/), + pathname: expect.stringMatching(/^\/assets\/index-.+\.js$/), rel: 'modulepreload', as: 'script' } diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts index e2f41d893021c3..faa1dc267d8d02 100644 --- a/playground/css/__tests__/css.spec.ts +++ b/playground/css/__tests__/css.spec.ts @@ -64,7 +64,7 @@ test('css import from js', async () => { test('css import asset with space', async () => { const importedWithSpace = await page.$('.import-with-space') - expect(await getBg(importedWithSpace)).toMatch(/.*ok\..*png/) + expect(await getBg(importedWithSpace)).toMatch(/.*ok-.*png/) }) test('postcss config', async () => { @@ -90,7 +90,7 @@ test('sass', async () => { isBuild ? /base64/ : '/nested/icon.png' ) expect(await getBg(urlStartsWithVariable)).toMatch( - isBuild ? /ok\.\w+\.png/ : `${viteTestUrl}/ok.png` + isBuild ? /ok-\w+\.png/ : `${viteTestUrl}/ok.png` ) expect(await getColor(partialImport)).toBe('orchid') @@ -124,7 +124,7 @@ test('less', async () => { isBuild ? /base64/ : '/nested/icon.png' ) expect(await getBg(urlStartsWithVariable)).toMatch( - isBuild ? /ok\.\w+\.png/ : `${viteTestUrl}/ok.png` + isBuild ? /ok-\w+\.png/ : `${viteTestUrl}/ok.png` ) editFile('less.less', (code) => code.replace('@color: blue', '@color: red')) @@ -297,8 +297,8 @@ test('async chunk', async () => { if (isBuild) { // assert that the css is extracted into its own file instead of in the // main css file - expect(findAssetFile(/index\.\w+\.css$/)).not.toMatch('teal') - expect(findAssetFile(/async\.\w+\.css$/)).toMatch('.async{color:teal}') + expect(findAssetFile(/index-\w+\.css$/)).not.toMatch('teal') + expect(findAssetFile(/async-\w+\.css$/)).toMatch('.async{color:teal}') } else { // test hmr editFile('async.css', (code) => code.replace('color: teal', 'color: blue')) @@ -316,8 +316,8 @@ test('treeshaken async chunk', async () => { ).toBeNull() // assert that the css is not present anywhere expect(findAssetFile(/\.css$/)).not.toMatch('plum') - expect(findAssetFile(/index\.\w+\.js$/)).not.toMatch('.async{color:plum}') - expect(findAssetFile(/async\.\w+\.js$/)).not.toMatch('.async{color:plum}') + expect(findAssetFile(/index-\w+\.js$/)).not.toMatch('.async{color:plum}') + expect(findAssetFile(/async-\w+\.js$/)).not.toMatch('.async{color:plum}') // should have no chunk! expect(findAssetFile(/async-treeshaken/)).toBe('') } else { @@ -416,7 +416,7 @@ test('minify css', async () => { } // should keep the rgba() syntax - const cssFile = findAssetFile(/index\.\w+\.css$/) + const cssFile = findAssetFile(/index-\w+\.css$/) expect(cssFile).toMatch('rgba(') expect(cssFile).not.toMatch('#ffff00b3') }) diff --git a/playground/css/vite.config-relative-base.js b/playground/css/vite.config-relative-base.js index ae09766c0768ac..7b54a149bcd987 100644 --- a/playground/css/vite.config-relative-base.js +++ b/playground/css/vite.config-relative-base.js @@ -15,8 +15,8 @@ module.exports = { rollupOptions: { output: { entryFileNames: 'entries/[name].js', - chunkFileNames: 'chunks/[name].[hash].js', - assetFileNames: 'other-assets/[name].[hash][extname]' + chunkFileNames: 'chunks/[name]-[hash].js', + assetFileNames: 'other-assets/[name]-[hash][extname]' } } }, diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index a438ce00d2d62b..c9a4c4ffe34d5e 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -185,7 +185,7 @@ test('tree-shake eager css', async () => { ) if (isBuild) { - const content = findAssetFile(/index\.\w+\.js/) + const content = findAssetFile(/index-\w+\.js/) expect(content).not.toMatch('.tree-shake-eager-css') } }) diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index cee22bbd39c981..e2e6fc4787cccc 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -76,7 +76,7 @@ test('should load dynamic import with css', async () => { test('asset url', async () => { expect(await page.textContent('#asset-path')).toMatch( - isBuild ? /\/assets\/vite\.\w+\.svg/ : '/vite.svg' + isBuild ? /\/assets\/vite-\w+\.svg/ : '/vite.svg' ) }) diff --git a/playground/legacy/vite.config-multiple-output.js b/playground/legacy/vite.config-multiple-output.js index 6d958bd892d621..7940ed5db9f386 100644 --- a/playground/legacy/vite.config-multiple-output.js +++ b/playground/legacy/vite.config-multiple-output.js @@ -10,14 +10,14 @@ export default defineConfig({ output: [ { assetFileNames() { - return 'assets/subdir/[name].[hash][extname]' + return 'assets/subdir/[name]-[hash][extname]' }, entryFileNames: `assets/subdir/[name].js`, chunkFileNames: `assets/subdir/[name].js` }, { assetFileNames() { - return 'assets/subdir/[name].[hash][extname]' + return 'assets/subdir/[name]-[hash][extname]' }, entryFileNames: `assets/anotherSubdir/[name].js`, chunkFileNames: `assets/anotherSubdir/[name].js` diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index 0f9b837aab2b3f..452f6b19ed094a 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -36,7 +36,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}.mjs"\)/) }) test('@import hoist', async () => { diff --git a/playground/preload/__tests__/preload.spec.ts b/playground/preload/__tests__/preload.spec.ts index a133fa7b96bc50..dc93f51ba2b700 100644 --- a/playground/preload/__tests__/preload.spec.ts +++ b/playground/preload/__tests__/preload.spec.ts @@ -17,10 +17,10 @@ describe.runIf(isBuild)('build', () => { await page.goto(viteTestUrl + '/#/hello') const html = await page.content() expect(html).toMatch( - /link rel="modulepreload".*?href=".*?\/assets\/Hello\.\w{8}\.js"/ + /link rel="modulepreload".*?href=".*?\/assets\/Hello-\w{8}\.js"/ ) expect(html).toMatch( - /link rel="stylesheet".*?href=".*?\/assets\/Hello\.\w{8}\.css"/ + /link rel="stylesheet".*?href=".*?\/assets\/Hello-\w{8}\.css"/ ) }) }) diff --git a/playground/preload/__tests__/resolve-deps/preload-resolve-deps.spec.ts b/playground/preload/__tests__/resolve-deps/preload-resolve-deps.spec.ts index d7230ad7708f13..b587f78b08c207 100644 --- a/playground/preload/__tests__/resolve-deps/preload-resolve-deps.spec.ts +++ b/playground/preload/__tests__/resolve-deps/preload-resolve-deps.spec.ts @@ -17,11 +17,11 @@ describe.runIf(isBuild)('build', () => { await page.goto(viteTestUrl + '/#/hello') const html = await page.content() expect(html).toMatch( - /link rel="modulepreload".*?href="http.*?\/Hello\.\w{8}\.js"/ + /link rel="modulepreload".*?href="http.*?\/Hello-\w{8}\.js"/ ) expect(html).toMatch(/link rel="modulepreload".*?href="\/preloaded.js"/) expect(html).toMatch( - /link rel="stylesheet".*?href="http.*?\/Hello\.\w{8}\.css"/ + /link rel="stylesheet".*?href="http.*?\/Hello-\w{8}\.css"/ ) }) }) diff --git a/playground/ssr-vue/__tests__/ssr-vue.spec.ts b/playground/ssr-vue/__tests__/ssr-vue.spec.ts index 2b66edc4d469f7..3bcb2b3ff07dee 100644 --- a/playground/ssr-vue/__tests__/ssr-vue.spec.ts +++ b/playground/ssr-vue/__tests__/ssr-vue.spec.ts @@ -39,16 +39,16 @@ test('/about', async () => { if (isBuild) { // assert correct preload directive generation for async chunks and CSS expect(aboutHtml).not.toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/ ) expect(aboutHtml).not.toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/ ) expect(aboutHtml).toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/About\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/ ) expect(aboutHtml).toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/About\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/ ) } }) @@ -69,13 +69,13 @@ test('/external', async () => { if (isBuild) { // assert correct preload directive generation for async chunks and CSS expect(externalHtml).not.toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/ ) expect(externalHtml).not.toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/ ) expect(externalHtml).toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/External\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/External-\w{8}\.js"/ ) } }) @@ -93,23 +93,23 @@ test('/', async () => { if (isBuild) { // assert correct preload directive generation for async chunks and CSS expect(html).toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/ ) expect(html).toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/ ) // JSX component preload registration expect(html).toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/Foo\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/Foo-\w{8}\.js"/ ) expect(html).toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/Foo\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/Foo-\w{8}\.css"/ ) expect(html).not.toMatch( - /link rel="modulepreload".*?href="\/test\/assets\/About\.\w{8}\.js"/ + /link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/ ) expect(html).not.toMatch( - /link rel="stylesheet".*?href="\/test\/assets\/About\.\w{8}\.css"/ + /link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/ ) } }) @@ -135,7 +135,7 @@ test('asset', async () => { }) const img = await page.$('img') expect(await img.getAttribute('src')).toMatch( - isBuild ? /\/test\/assets\/logo\.\w{8}\.png/ : '/src/assets/logo.png' + isBuild ? /\/test\/assets\/logo-\w{8}\.png/ : '/src/assets/logo.png' ) }) @@ -194,7 +194,7 @@ test.runIf(isBuild)('dynamic css file should be preloaded', async () => { await page.goto(url) const homeHtml = await (await fetch(url)).text() const re = - /link rel="modulepreload".*?href="\/test\/assets\/(Home\.\w{8}\.js)"/ + /link rel="modulepreload".*?href="\/test\/assets\/(Home-\w{8}\.js)"/ const filename = re.exec(homeHtml)[1] const manifest = ( await import( diff --git a/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts b/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts index 6f88c4331a553c..e215abe862825b 100644 --- a/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts +++ b/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts @@ -12,6 +12,6 @@ test('/', async () => { }) test.runIf(isBuild)('inlineDynamicImports', () => { - const dynamicJsContent = findAssetFile(/dynamic\.\w+\.js/, 'worker') + const dynamicJsContent = findAssetFile(/dynamic-\w+\.js/, 'worker') expect(dynamicJsContent).toBe('') }) diff --git a/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts b/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts index 777ee09bf33855..c3636319e150da 100644 --- a/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts +++ b/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts @@ -3,7 +3,7 @@ import { isBuild, page } from '~utils' test('should render', async () => { const expected = isBuild - ? /assets\/asset\.[0-9a-f]+\.png/ + ? /assets\/asset-[0-9a-f]+\.png/ : 'http://localhost/server-origin/test/assets/asset.png' expect(await page.getAttribute('img', 'src')).toMatch(expected) diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 51dbf82a480aff..fac145bfa4f457 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -116,7 +116,7 @@ describe('css modules', () => { describe('asset reference', () => { const assetMatch = isBuild - ? /\/assets\/asset\.\w{8}\.png/ + ? /\/assets\/asset-\w{8}\.png/ : '/assets/asset.png' test('should not 404', () => { @@ -153,7 +153,7 @@ describe('asset reference', () => { test('relative url from