Skip to content

Commit cc2adb3

Browse files
authoredNov 17, 2022
feat: align default chunk and asset file names with rollup (#10927)
1 parent 9f54c6a commit cc2adb3

34 files changed

+133
-139
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"typescript": "^4.6.4",
9090
"unbuild": "^0.9.4",
9191
"vite": "workspace:*",
92-
"vitepress": "^1.0.0-alpha.28",
92+
"vitepress": "^1.0.0-alpha.29",
9393
"vitest": "^0.25.1",
9494
"vue": "^3.2.45"
9595
},

‎packages/plugin-legacy/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
298298
| string
299299
| ((chunkInfo: PreRenderedChunk) => string)
300300
| undefined,
301-
defaultFileName = '[name]-legacy.[hash].js'
301+
defaultFileName = '[name]-legacy-[hash].js'
302302
): string | ((chunkInfo: PreRenderedChunk) => string) => {
303303
if (!fileNames) {
304304
return path.posix.join(config.build.assetsDir, defaultFileName)

‎packages/vite/src/node/build.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,13 @@ async function doBuild(
576576
: libOptions
577577
? ({ name }) =>
578578
resolveLibFilename(libOptions, format, name, config.root, jsExt)
579-
: path.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
579+
: path.posix.join(options.assetsDir, `[name]-[hash].${jsExt}`),
580580
chunkFileNames: libOptions
581-
? `[name].[hash].${jsExt}`
582-
: path.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
581+
? `[name]-[hash].${jsExt}`
582+
: path.posix.join(options.assetsDir, `[name]-[hash].${jsExt}`),
583583
assetFileNames: libOptions
584584
? `[name].[ext]`
585-
: path.posix.join(options.assetsDir, `[name].[hash].[ext]`),
585+
: path.posix.join(options.assetsDir, `[name]-[hash].[ext]`),
586586
inlineDynamicImports:
587587
output.format === 'umd' ||
588588
output.format === 'iife' ||

‎packages/vite/src/node/plugins/worker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ export async function bundleWorkerEntry(
7979
} = await bundle.generate({
8080
entryFileNames: path.posix.join(
8181
config.build.assetsDir,
82-
'[name].[hash].js'
82+
'[name]-[hash].js'
8383
),
8484
chunkFileNames: path.posix.join(
8585
config.build.assetsDir,
86-
'[name].[hash].js'
86+
'[name]-[hash].js'
8787
),
8888
assetFileNames: path.posix.join(
8989
config.build.assetsDir,
90-
'[name].[hash].[ext]'
90+
'[name]-[hash].[ext]'
9191
),
9292
...workerConfig,
9393
format,

‎playground/assets/__tests__/assets.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '~utils'
2020

2121
const assetMatch = isBuild
22-
? /\/foo\/assets\/asset\.\w{8}\.png/
22+
? /\/foo\/assets\/asset-\w{8}\.png/
2323
: '/foo/nested/asset.png'
2424

2525
const iconMatch = `/foo/icon.png`
@@ -209,8 +209,8 @@ describe('image', () => {
209209
srcset.split(', ').forEach((s) => {
210210
expect(s).toMatch(
211211
isBuild
212-
? /\/foo\/assets\/asset\.\w{8}\.png \dx/
213-
: /\/foo\/nested\/asset\.png \dx/
212+
? /\/foo\/assets\/asset-\w{8}\.png \dx/
213+
: /\/foo\/nested\/asset.png \dx/
214214
)
215215
})
216216
})
@@ -338,7 +338,7 @@ describe.runIf(isBuild)('css and assets in css in build watch', () => {
338338
test('css will not be lost and css does not contain undefined', async () => {
339339
editFile('index.html', (code) => code.replace('Assets', 'assets'), true)
340340
await notifyRebuildComplete(watcher)
341-
const cssFile = findAssetFile(/index\.\w+\.css$/, 'foo')
341+
const cssFile = findAssetFile(/index-\w+\.css$/, 'foo')
342342
expect(cssFile).not.toBe('')
343343
expect(cssFile).not.toMatch(/undefined/)
344344
})

‎playground/assets/__tests__/relative-base/relative-base-assets.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '~utils'
1111

1212
const absoluteAssetMatch = isBuild
13-
? /http.*\/other-assets\/asset\.\w{8}\.png/
13+
? /http.*\/other-assets\/asset-\w{8}\.png/
1414
: '/nested/asset.png'
1515

1616
// Asset URLs in CSS are relative to the same dir, the computed
@@ -20,7 +20,7 @@ const cssBgAssetMatch = absoluteAssetMatch
2020
const iconMatch = `/icon.png`
2121

2222
const absoluteIconMatch = isBuild
23-
? /http.*\/icon\.\w{8}\.png/
23+
? /http.*\/icon-\w{8}\.png/
2424
: '/nested/icon.png'
2525

2626
const absolutePublicIconMatch = isBuild ? /http.*\/icon\.png/ : '/icon.png'
@@ -143,7 +143,7 @@ describe.runIf(isBuild)('index.css URLs', () => {
143143
})
144144

145145
test('relative asset URL', () => {
146-
expect(css).toMatch(`./asset.`)
146+
expect(css).toMatch(`./asset-`)
147147
})
148148

149149
test('preserve postfix query/hash', () => {
@@ -158,7 +158,7 @@ describe('image', () => {
158158
srcset.split(', ').forEach((s) => {
159159
expect(s).toMatch(
160160
isBuild
161-
? /other-assets\/asset\.\w{8}\.png \dx/
161+
? /other-assets\/asset-\w{8}\.png \dx/
162162
: /\.\/nested\/asset\.png \dx/
163163
)
164164
})
@@ -191,14 +191,14 @@ test('?raw import', async () => {
191191

192192
test('?url import', async () => {
193193
expect(await page.textContent('.url')).toMatch(
194-
isBuild ? /http.*\/other-assets\/foo\.\w{8}\.js/ : `/foo.js`
194+
isBuild ? /http.*\/other-assets\/foo-\w{8}\.js/ : `/foo.js`
195195
)
196196
})
197197

198198
test('?url import on css', async () => {
199199
const txt = await page.textContent('.url-css')
200200
expect(txt).toMatch(
201-
isBuild ? /http.*\/other-assets\/icons\.\w{8}\.css/ : '/css/icons.css'
201+
isBuild ? /http.*\/other-assets\/icons-\w{8}\.css/ : '/css/icons.css'
202202
)
203203
})
204204

‎playground/assets/__tests__/runtime-base/runtime-base-assets.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '~utils'
1010

1111
const absoluteAssetMatch = isBuild
12-
? /\/other-assets\/asset\.\w{8}\.png/
12+
? /\/other-assets\/asset-\w{8}\.png/
1313
: '/nested/asset.png'
1414

1515
// Asset URLs in CSS are relative to the same dir, the computed
@@ -19,7 +19,7 @@ const cssBgAssetMatch = absoluteAssetMatch
1919
const iconMatch = `/icon.png`
2020

2121
const absoluteIconMatch = isBuild
22-
? /\/other-assets\/icon\.\w{8}\.png/
22+
? /\/other-assets\/icon-\w{8}\.png/
2323
: '/nested/icon.png'
2424

2525
const absolutePublicIconMatch = isBuild ? /\/icon\.png/ : '/icon.png'
@@ -137,11 +137,11 @@ describe('css url() references', () => {
137137
describe.runIf(isBuild)('index.css URLs', () => {
138138
let css: string
139139
beforeAll(() => {
140-
css = findAssetFile(/index.*\.css$/, '', 'other-assets')
140+
css = findAssetFile(/index-\w{8}\.css$/, '', 'other-assets')
141141
})
142142

143143
test('relative asset URL', () => {
144-
expect(css).toMatch(`./asset.`)
144+
expect(css).toMatch(`./asset-`)
145145
})
146146

147147
test('preserve postfix query/hash', () => {
@@ -156,7 +156,7 @@ describe('image', () => {
156156
srcset.split(', ').forEach((s) => {
157157
expect(s).toMatch(
158158
isBuild
159-
? /other-assets\/asset\.\w{8}\.png \dx/
159+
? /other-assets\/asset-\w{8}\.png \dx/
160160
: /\.\/nested\/asset\.png \dx/
161161
)
162162
})
@@ -189,14 +189,14 @@ test('?raw import', async () => {
189189

190190
test('?url import', async () => {
191191
expect(await page.textContent('.url')).toMatch(
192-
isBuild ? /\/other-assets\/foo\.\w{8}\.js/ : `/foo.js`
192+
isBuild ? /\/other-assets\/foo-\w{8}\.js/ : `/foo.js`
193193
)
194194
})
195195

196196
test('?url import on css', async () => {
197197
const txt = await page.textContent('.url-css')
198198
expect(txt).toMatch(
199-
isBuild ? /\/other-assets\/icons\.\w{8}\.css/ : '/css/icons.css'
199+
isBuild ? /\/other-assets\/icons-\w{8}\.css/ : '/css/icons.css'
200200
)
201201
})
202202

‎playground/assets/vite.config-relative-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = {
1515
rollupOptions: {
1616
output: {
1717
entryFileNames: 'entries/[name].js',
18-
chunkFileNames: 'chunks/[name].[hash].js',
19-
assetFileNames: 'other-assets/[name].[hash][extname]'
18+
chunkFileNames: 'chunks/[name]-[hash].js',
19+
assetFileNames: 'other-assets/[name]-[hash][extname]'
2020
}
2121
}
2222
},

‎playground/assets/vite.config-runtime-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module.exports = {
2222
rollupOptions: {
2323
output: {
2424
entryFileNames: 'entries/[name].js',
25-
chunkFileNames: 'chunks/[name].[hash].js',
26-
assetFileNames: 'other-assets/[name].[hash][extname]'
25+
chunkFileNames: 'chunks/[name]-[hash].js',
26+
assetFileNames: 'other-assets/[name]-[hash][extname]'
2727
}
2828
}
2929
},

‎playground/backend-integration/__tests__/backend-integration.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '~utils'
1313

1414
const outerAssetMatch = isBuild
15-
? /\/dev\/assets\/logo\.\w{8}\.png/
15+
? /\/dev\/assets\/logo-\w{8}\.png/
1616
: /\/dev\/@fs\/.+?\/images\/logo\.png/
1717

1818
test('should have no 404s', () => {

‎playground/css-dynamic-import/__tests__/css-dynamic-import.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,32 @@ baseOptions.forEach(({ base, label }) => {
6666
expect(await getColor('.css-dynamic-import')).toBe('green')
6767
expect(await getLinks()).toEqual([
6868
{
69-
pathname: expect.stringMatching(/^\/assets\/index\..+\.css$/),
69+
pathname: expect.stringMatching(/^\/assets\/index-.+\.css$/),
7070
rel: 'stylesheet',
7171
as: ''
7272
},
7373
{
74-
pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.css$/),
74+
pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.css$/),
7575
rel: 'preload',
7676
as: 'style'
7777
},
7878
{
79-
pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.js$/),
79+
pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.js$/),
8080
rel: 'modulepreload',
8181
as: 'script'
8282
},
8383
{
84-
pathname: expect.stringMatching(/^\/assets\/dynamic\..+\.css$/),
84+
pathname: expect.stringMatching(/^\/assets\/dynamic-.+\.css$/),
8585
rel: 'stylesheet',
8686
as: ''
8787
},
8888
{
89-
pathname: expect.stringMatching(/^\/assets\/static\..+\.js$/),
89+
pathname: expect.stringMatching(/^\/assets\/static-.+\.js$/),
9090
rel: 'modulepreload',
9191
as: 'script'
9292
},
9393
{
94-
pathname: expect.stringMatching(/^\/assets\/index\..+\.js$/),
94+
pathname: expect.stringMatching(/^\/assets\/index-.+\.js$/),
9595
rel: 'modulepreload',
9696
as: 'script'
9797
}

‎playground/css/__tests__/css.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test('css import from js', async () => {
6464
test('css import asset with space', async () => {
6565
const importedWithSpace = await page.$('.import-with-space')
6666

67-
expect(await getBg(importedWithSpace)).toMatch(/.*ok\..*png/)
67+
expect(await getBg(importedWithSpace)).toMatch(/.*\/ok.*\.png/)
6868
})
6969

7070
test('postcss config', async () => {
@@ -90,7 +90,7 @@ test('sass', async () => {
9090
isBuild ? /base64/ : '/nested/icon.png'
9191
)
9292
expect(await getBg(urlStartsWithVariable)).toMatch(
93-
isBuild ? /ok\.\w+\.png/ : `${viteTestUrl}/ok.png`
93+
isBuild ? /ok-\w+\.png/ : `${viteTestUrl}/ok.png`
9494
)
9595
expect(await getColor(partialImport)).toBe('orchid')
9696

@@ -124,7 +124,7 @@ test('less', async () => {
124124
isBuild ? /base64/ : '/nested/icon.png'
125125
)
126126
expect(await getBg(urlStartsWithVariable)).toMatch(
127-
isBuild ? /ok\.\w+\.png/ : `${viteTestUrl}/ok.png`
127+
isBuild ? /ok-\w+\.png/ : `${viteTestUrl}/ok.png`
128128
)
129129

130130
editFile('less.less', (code) => code.replace('@color: blue', '@color: red'))
@@ -297,8 +297,8 @@ test('async chunk', async () => {
297297
if (isBuild) {
298298
// assert that the css is extracted into its own file instead of in the
299299
// main css file
300-
expect(findAssetFile(/index\.\w+\.css$/)).not.toMatch('teal')
301-
expect(findAssetFile(/async\.\w+\.css$/)).toMatch('.async{color:teal}')
300+
expect(findAssetFile(/index-\w+\.css$/)).not.toMatch('teal')
301+
expect(findAssetFile(/async-\w+\.css$/)).toMatch('.async{color:teal}')
302302
} else {
303303
// test hmr
304304
editFile('async.css', (code) => code.replace('color: teal', 'color: blue'))
@@ -316,8 +316,8 @@ test('treeshaken async chunk', async () => {
316316
).toBeNull()
317317
// assert that the css is not present anywhere
318318
expect(findAssetFile(/\.css$/)).not.toMatch('plum')
319-
expect(findAssetFile(/index\.\w+\.js$/)).not.toMatch('.async{color:plum}')
320-
expect(findAssetFile(/async\.\w+\.js$/)).not.toMatch('.async{color:plum}')
319+
expect(findAssetFile(/index-\w+\.js$/)).not.toMatch('.async{color:plum}')
320+
expect(findAssetFile(/async-\w+\.js$/)).not.toMatch('.async{color:plum}')
321321
// should have no chunk!
322322
expect(findAssetFile(/async-treeshaken/)).toBe('')
323323
} else {
@@ -416,7 +416,7 @@ test('minify css', async () => {
416416
}
417417

418418
// should keep the rgba() syntax
419-
const cssFile = findAssetFile(/index\.\w+\.css$/)
419+
const cssFile = findAssetFile(/index-\w+\.css$/)
420420
expect(cssFile).toMatch('rgba(')
421421
expect(cssFile).not.toMatch('#ffff00b3')
422422
})

‎playground/css/vite.config-relative-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = {
1515
rollupOptions: {
1616
output: {
1717
entryFileNames: 'entries/[name].js',
18-
chunkFileNames: 'chunks/[name].[hash].js',
19-
assetFileNames: 'other-assets/[name].[hash][extname]'
18+
chunkFileNames: 'chunks/[name]-[hash].js',
19+
assetFileNames: 'other-assets/[name]-[hash][extname]'
2020
}
2121
}
2222
},

‎playground/glob-import/__tests__/glob-import.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ test('tree-shake eager css', async () => {
185185
)
186186

187187
if (isBuild) {
188-
const content = findAssetFile(/index\.\w+\.js/)
188+
const content = findAssetFile(/index-\w+\.js/)
189189
expect(content).not.toMatch('.tree-shake-eager-css')
190190
}
191191
})

‎playground/legacy/__tests__/legacy.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('should load dynamic import with css', async () => {
7676

7777
test('asset url', async () => {
7878
expect(await page.textContent('#asset-path')).toMatch(
79-
isBuild ? /\/assets\/vite\.\w+\.svg/ : '/vite.svg'
79+
isBuild ? /\/assets\/vite-\w+\.svg/ : '/vite.svg'
8080
)
8181
})
8282

@@ -116,6 +116,6 @@ describe.runIf(isBuild)('build', () => {
116116

117117
test('includes structuredClone polyfill which is supported after core-js v3', () => {
118118
expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"')
119-
expect(findAssetFile(/polyfills\./)).toMatch('"structuredClone"')
119+
expect(findAssetFile(/polyfills-\w{8}\./)).toMatch('"structuredClone"')
120120
})
121121
})

‎playground/legacy/vite.config-multiple-output.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export default defineConfig({
1010
output: [
1111
{
1212
assetFileNames() {
13-
return 'assets/subdir/[name].[hash][extname]'
13+
return 'assets/subdir/[name]-[hash][extname]'
1414
},
1515
entryFileNames: `assets/subdir/[name].js`,
1616
chunkFileNames: `assets/subdir/[name].js`
1717
},
1818
{
1919
assetFileNames() {
20-
return 'assets/subdir/[name].[hash][extname]'
20+
return 'assets/subdir/[name]-[hash][extname]'
2121
},
2222
entryFileNames: `assets/anotherSubdir/[name].js`,
2323
chunkFileNames: `assets/anotherSubdir/[name].js`

‎playground/lib/__tests__/lib.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe.runIf(isBuild)('build', () => {
3636
expect(code).not.toMatch('__vitePreload')
3737

3838
// Test that library chunks are hashed
39-
expect(code).toMatch(/await import\("\.\/message.[a-z\d]{8}.mjs"\)/)
39+
expect(code).toMatch(/await import\("\.\/message-[a-z\d]{8}.mjs"\)/)
4040
})
4141

4242
test('@import hoist', async () => {

‎playground/preload/__tests__/preload.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ describe.runIf(isBuild)('build', () => {
1717
await page.goto(viteTestUrl + '/#/hello')
1818
const html = await page.content()
1919
expect(html).toMatch(
20-
/link rel="modulepreload".*?href=".*?\/assets\/Hello\.\w{8}\.js"/
20+
/link rel="modulepreload".*?href=".*?\/assets\/Hello-\w{8}\.js"/
2121
)
2222
expect(html).toMatch(
23-
/link rel="stylesheet".*?href=".*?\/assets\/Hello\.\w{8}\.css"/
23+
/link rel="stylesheet".*?href=".*?\/assets\/Hello-\w{8}\.css"/
2424
)
2525
})
2626
})

‎playground/preload/__tests__/resolve-deps/preload-resolve-deps.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ describe.runIf(isBuild)('build', () => {
1717
await page.goto(viteTestUrl + '/#/hello')
1818
const html = await page.content()
1919
expect(html).toMatch(
20-
/link rel="modulepreload".*?href="http.*?\/Hello\.\w{8}\.js"/
20+
/link rel="modulepreload".*?href="http.*?\/Hello-\w{8}\.js"/
2121
)
2222
expect(html).toMatch(/link rel="modulepreload".*?href="\/preloaded.js"/)
2323
expect(html).toMatch(
24-
/link rel="stylesheet".*?href="http.*?\/Hello\.\w{8}\.css"/
24+
/link rel="stylesheet".*?href="http.*?\/Hello-\w{8}\.css"/
2525
)
2626
})
2727
})

‎playground/ssr-vue/__tests__/ssr-vue.spec.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ test('/about', async () => {
3939
if (isBuild) {
4040
// assert correct preload directive generation for async chunks and CSS
4141
expect(aboutHtml).not.toMatch(
42-
/link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/
42+
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/
4343
)
4444
expect(aboutHtml).not.toMatch(
45-
/link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/
45+
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/
4646
)
4747
expect(aboutHtml).toMatch(
48-
/link rel="modulepreload".*?href="\/test\/assets\/About\.\w{8}\.js"/
48+
/link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/
4949
)
5050
expect(aboutHtml).toMatch(
51-
/link rel="stylesheet".*?href="\/test\/assets\/About\.\w{8}\.css"/
51+
/link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/
5252
)
5353
}
5454
})
@@ -69,13 +69,13 @@ test('/external', async () => {
6969
if (isBuild) {
7070
// assert correct preload directive generation for async chunks and CSS
7171
expect(externalHtml).not.toMatch(
72-
/link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/
72+
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/
7373
)
7474
expect(externalHtml).not.toMatch(
75-
/link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/
75+
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/
7676
)
7777
expect(externalHtml).toMatch(
78-
/link rel="modulepreload".*?href="\/test\/assets\/External\.\w{8}\.js"/
78+
/link rel="modulepreload".*?href="\/test\/assets\/External-\w{8}\.js"/
7979
)
8080
}
8181
})
@@ -93,23 +93,23 @@ test('/', async () => {
9393
if (isBuild) {
9494
// assert correct preload directive generation for async chunks and CSS
9595
expect(html).toMatch(
96-
/link rel="modulepreload".*?href="\/test\/assets\/Home\.\w{8}\.js"/
96+
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/
9797
)
9898
expect(html).toMatch(
99-
/link rel="stylesheet".*?href="\/test\/assets\/Home\.\w{8}\.css"/
99+
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/
100100
)
101101
// JSX component preload registration
102102
expect(html).toMatch(
103-
/link rel="modulepreload".*?href="\/test\/assets\/Foo\.\w{8}\.js"/
103+
/link rel="modulepreload".*?href="\/test\/assets\/Foo-\w{8}\.js"/
104104
)
105105
expect(html).toMatch(
106-
/link rel="stylesheet".*?href="\/test\/assets\/Foo\.\w{8}\.css"/
106+
/link rel="stylesheet".*?href="\/test\/assets\/Foo-\w{8}\.css"/
107107
)
108108
expect(html).not.toMatch(
109-
/link rel="modulepreload".*?href="\/test\/assets\/About\.\w{8}\.js"/
109+
/link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/
110110
)
111111
expect(html).not.toMatch(
112-
/link rel="stylesheet".*?href="\/test\/assets\/About\.\w{8}\.css"/
112+
/link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/
113113
)
114114
}
115115
})
@@ -135,7 +135,7 @@ test('asset', async () => {
135135
})
136136
const img = await page.$('img')
137137
expect(await img.getAttribute('src')).toMatch(
138-
isBuild ? /\/test\/assets\/logo\.\w{8}\.png/ : '/src/assets/logo.png'
138+
isBuild ? /\/test\/assets\/logo-\w{8}\.png/ : '/src/assets/logo.png'
139139
)
140140
})
141141

@@ -194,7 +194,7 @@ test.runIf(isBuild)('dynamic css file should be preloaded', async () => {
194194
await page.goto(url)
195195
const homeHtml = await (await fetch(url)).text()
196196
const re =
197-
/link rel="modulepreload".*?href="\/test\/assets\/(Home\.\w{8}\.js)"/
197+
/link rel="modulepreload".*?href="\/test\/assets\/(Home-\w{8}\.js)"/
198198
const filename = re.exec(homeHtml)[1]
199199
const manifest = (
200200
await import(

‎playground/ssr-webworker/__tests__/ssr-webworker.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ test('/', async () => {
1212
})
1313

1414
test.runIf(isBuild)('inlineDynamicImports', () => {
15-
const dynamicJsContent = findAssetFile(/dynamic\.\w+\.js/, 'worker')
15+
const dynamicJsContent = findAssetFile(/dynamic-\w+\.js/, 'worker')
1616
expect(dynamicJsContent).toBe('')
1717
})

‎playground/vue-server-origin/__tests__/vue-server-origin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isBuild, page } from '~utils'
33

44
test('should render', async () => {
55
const expected = isBuild
6-
? /assets\/asset\.[\da-f]+\.png/
6+
? /assets\/asset-[\da-f]+\.png/
77
: 'http://localhost/server-origin/test/assets/asset.png'
88

99
expect(await page.getAttribute('img', 'src')).toMatch(expected)

‎playground/vue/__tests__/vue.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('css modules', () => {
116116

117117
describe('asset reference', () => {
118118
const assetMatch = isBuild
119-
? /\/assets\/asset\.\w{8}\.png/
119+
? /\/assets\/asset-\w{8}\.png/
120120
: '/assets/asset.png'
121121

122122
test('should not 404', () => {
@@ -153,7 +153,7 @@ describe('asset reference', () => {
153153

154154
test('relative url from <style>', async () => {
155155
const assetMatch = isBuild
156-
? /\/assets\/asset\.\w{8}\.png/
156+
? /\/assets\/asset-\w{8}\.png/
157157
: '/assets/asset.png'
158158
expect(await getBg('.relative-style-url')).toMatch(assetMatch)
159159
})

‎playground/worker/__tests__/es/es-worker.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('normal', async () => {
1717
)
1818
await untilUpdated(
1919
() => page.textContent('.asset-url'),
20-
isBuild ? '/es/assets/worker_asset.vite.svg' : '/es/vite.svg',
20+
isBuild ? '/es/assets/worker_asset-vite.svg' : '/es/vite.svg',
2121
true
2222
)
2323
})

‎playground/worker/__tests__/iife/iife-worker.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('normal', async () => {
1212
)
1313
await untilUpdated(
1414
() => page.textContent('.asset-url'),
15-
isBuild ? '/iife/assets/worker_asset.vite.svg' : '/iife/vite.svg',
15+
isBuild ? '/iife/assets/worker_asset-vite.svg' : '/iife/vite.svg',
1616
true
1717
)
1818
})

‎playground/worker/__tests__/relative-base/relative-base-worker.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('normal', async () => {
1717
)
1818
await untilUpdated(
1919
() => page.textContent('.asset-url'),
20-
isBuild ? '/worker-assets/worker_asset.vite' : '/vite.svg',
20+
isBuild ? '/worker-assets/worker_asset-vite' : '/vite.svg',
2121
true
2222
)
2323
})
@@ -65,7 +65,7 @@ describe.runIf(isBuild)('build', () => {
6565
'dist/relative-base/worker-entries'
6666
)
6767
const workerFiles = fs.readdirSync(workerEntriesDir)
68-
const worker = workerFiles.find((f) => f.includes('worker_entry.my-worker'))
68+
const worker = workerFiles.find((f) => f.includes('worker_entry-my-worker'))
6969
const workerContent = fs.readFileSync(
7070
path.resolve(workerEntriesDir, worker),
7171
'utf-8'

‎playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ describe.runIf(isBuild)('build', () => {
1414
const index = files.find((f) => f.includes('main-module'))
1515
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
1616
const indexSourcemap = getSourceMapUrl(content)
17-
const worker = files.find((f) => /^my-worker\.\w+\.js$/.test(f))
17+
const worker = files.find((f) => /^my-worker-\w+\.js$/.test(f))
1818
const workerContent = fs.readFileSync(
1919
path.resolve(assetsDir, worker),
2020
'utf-8'
2121
)
2222
const workerSourcemap = getSourceMapUrl(workerContent)
23-
const sharedWorker = files.find((f) =>
24-
/^my-shared-worker\.\w+\.js$/.test(f)
25-
)
23+
const sharedWorker = files.find((f) => /^my-shared-worker-\w+\.js$/.test(f))
2624
const sharedWorkerContent = fs.readFileSync(
2725
path.resolve(assetsDir, sharedWorker),
2826
'utf-8'
2927
)
3028
const sharedWorkerSourcemap = getSourceMapUrl(sharedWorkerContent)
3129
const possibleTsOutputWorker = files.find((f) =>
32-
/^possible-ts-output-worker\.\w+\.js$/.test(f)
30+
/^possible-ts-output-worker-\w+\.js$/.test(f)
3331
)
3432
const possibleTsOutputWorkerContent = fs.readFileSync(
3533
path.resolve(assetsDir, possibleTsOutputWorker),
@@ -39,7 +37,7 @@ describe.runIf(isBuild)('build', () => {
3937
possibleTsOutputWorkerContent
4038
)
4139
const workerNestedWorker = files.find((f) =>
42-
/^worker-nested-worker\.\w+\.js$/.test(f)
40+
/^worker-nested-worker-\w+\.js$/.test(f)
4341
)
4442
const workerNestedWorkerContent = fs.readFileSync(
4543
path.resolve(assetsDir, workerNestedWorker),
@@ -48,28 +46,28 @@ describe.runIf(isBuild)('build', () => {
4846
const workerNestedWorkerSourcemap = getSourceMapUrl(
4947
workerNestedWorkerContent
5048
)
51-
const subWorker = files.find((f) => /^sub-worker\.\w+\.js$/.test(f))
49+
const subWorker = files.find((f) => /^sub-worker-\w+\.js$/.test(f))
5250
const subWorkerContent = fs.readFileSync(
5351
path.resolve(assetsDir, subWorker),
5452
'utf-8'
5553
)
5654
const subWorkerSourcemap = getSourceMapUrl(subWorkerContent)
5755

58-
expect(files).toContainEqual(expect.stringMatching(/^index\.\w+\.js\.map$/))
56+
expect(files).toContainEqual(expect.stringMatching(/^index-\w+\.js\.map$/))
5957
expect(files).toContainEqual(
60-
expect.stringMatching(/^my-worker\.\w+\.js\.map$/)
58+
expect.stringMatching(/^my-worker-\w+\.js\.map$/)
6159
)
6260
expect(files).toContainEqual(
63-
expect.stringMatching(/^my-shared-worker\.\w+\.js\.map$/)
61+
expect.stringMatching(/^my-shared-worker-\w+\.js\.map$/)
6462
)
6563
expect(files).toContainEqual(
66-
expect.stringMatching(/^possible-ts-output-worker\.\w+\.js\.map$/)
64+
expect.stringMatching(/^possible-ts-output-worker-\w+\.js\.map$/)
6765
)
6866
expect(files).toContainEqual(
69-
expect.stringMatching(/^worker-nested-worker\.\w+\.js\.map$/)
67+
expect.stringMatching(/^worker-nested-worker-\w+\.js\.map$/)
7068
)
7169
expect(files).toContainEqual(
72-
expect.stringMatching(/^sub-worker\.\w+\.js\.map$/)
70+
expect.stringMatching(/^sub-worker-\w+\.js\.map$/)
7371
)
7472

7573
// sourcemap should exist and have a data URL

‎playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ describe.runIf(isBuild)('build', () => {
1414
const index = files.find((f) => f.includes('main-module'))
1515
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
1616
const indexSourcemap = getSourceMapUrl(content)
17-
const worker = files.find((f) => /^my-worker\.\w+\.js$/.test(f))
17+
const worker = files.find((f) => /^my-worker-\w+\.js$/.test(f))
1818
const workerContent = fs.readFileSync(
1919
path.resolve(assetsDir, worker),
2020
'utf-8'
2121
)
2222
const workerSourcemap = getSourceMapUrl(workerContent)
23-
const sharedWorker = files.find((f) =>
24-
/^my-shared-worker\.\w+\.js$/.test(f)
25-
)
23+
const sharedWorker = files.find((f) => /^my-shared-worker-\w+\.js$/.test(f))
2624
const sharedWorkerContent = fs.readFileSync(
2725
path.resolve(assetsDir, sharedWorker),
2826
'utf-8'
2927
)
3028
const sharedWorkerSourcemap = getSourceMapUrl(sharedWorkerContent)
3129
const possibleTsOutputWorker = files.find((f) =>
32-
/^possible-ts-output-worker\.\w+\.js$/.test(f)
30+
/^possible-ts-output-worker-\w+\.js$/.test(f)
3331
)
3432
const possibleTsOutputWorkerContent = fs.readFileSync(
3533
path.resolve(assetsDir, possibleTsOutputWorker),
@@ -39,7 +37,7 @@ describe.runIf(isBuild)('build', () => {
3937
possibleTsOutputWorkerContent
4038
)
4139
const workerNestedWorker = files.find((f) =>
42-
/^worker-nested-worker\.\w+\.js$/.test(f)
40+
/^worker-nested-worker-\w+\.js$/.test(f)
4341
)
4442
const workerNestedWorkerContent = fs.readFileSync(
4543
path.resolve(assetsDir, workerNestedWorker),
@@ -48,7 +46,7 @@ describe.runIf(isBuild)('build', () => {
4846
const workerNestedWorkerSourcemap = getSourceMapUrl(
4947
workerNestedWorkerContent
5048
)
51-
const subWorker = files.find((f) => /^sub-worker\.\w+\.js$/.test(f))
49+
const subWorker = files.find((f) => /^sub-worker-\w+\.js$/.test(f))
5250
const subWorkerContent = fs.readFileSync(
5351
path.resolve(assetsDir, subWorker),
5452
'utf-8'

‎playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@ describe.runIf(isBuild)('build', () => {
1313
const index = files.find((f) => f.includes('main-module'))
1414
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
1515
const indexSourcemap = getSourceMapUrl(content)
16-
const worker = files.find((f) => /^my-worker\.\w+\.js$/.test(f))
16+
const worker = files.find((f) => /^my-worker-\w+\.js$/.test(f))
1717
const workerContent = fs.readFileSync(
1818
path.resolve(assetsDir, worker),
1919
'utf-8'
2020
)
2121
const workerSourcemap = getSourceMapUrl(workerContent)
22-
const sharedWorker = files.find((f) =>
23-
/^my-shared-worker\.\w+\.js$/.test(f)
24-
)
22+
const sharedWorker = files.find((f) => /^my-shared-worker-\w+\.js$/.test(f))
2523
const sharedWorkerContent = fs.readFileSync(
2624
path.resolve(assetsDir, sharedWorker),
2725
'utf-8'
2826
)
2927
const sharedWorkerSourcemap = getSourceMapUrl(sharedWorkerContent)
3028
const possibleTsOutputWorker = files.find((f) =>
31-
/^possible-ts-output-worker\.\w+\.js$/.test(f)
29+
/^possible-ts-output-worker-\w+\.js$/.test(f)
3230
)
3331
const possibleTsOutputWorkerContent = fs.readFileSync(
3432
path.resolve(assetsDir, possibleTsOutputWorker),
@@ -38,7 +36,7 @@ describe.runIf(isBuild)('build', () => {
3836
possibleTsOutputWorkerContent
3937
)
4038
const workerNestedWorker = files.find((f) =>
41-
/^worker-nested-worker\.\w+\.js$/.test(f)
39+
/^worker-nested-worker-\w+\.js$/.test(f)
4240
)
4341
const workerNestedWorkerContent = fs.readFileSync(
4442
path.resolve(assetsDir, workerNestedWorker),
@@ -47,41 +45,41 @@ describe.runIf(isBuild)('build', () => {
4745
const workerNestedWorkerSourcemap = getSourceMapUrl(
4846
workerNestedWorkerContent
4947
)
50-
const subWorker = files.find((f) => /^sub-worker\.\w+\.js$/.test(f))
48+
const subWorker = files.find((f) => /^sub-worker-\w+\.js$/.test(f))
5149
const subWorkerContent = fs.readFileSync(
5250
path.resolve(assetsDir, subWorker),
5351
'utf-8'
5452
)
5553
const subWorkerSourcemap = getSourceMapUrl(subWorkerContent)
5654

57-
expect(files).toContainEqual(expect.stringMatching(/^index\.\w+\.js\.map$/))
55+
expect(files).toContainEqual(expect.stringMatching(/^index-\w+\.js\.map$/))
5856
expect(files).toContainEqual(
59-
expect.stringMatching(/^my-worker\.\w+\.js\.map$/)
57+
expect.stringMatching(/^my-worker-\w+\.js\.map$/)
6058
)
6159
expect(files).toContainEqual(
62-
expect.stringMatching(/^my-shared-worker\.\w+\.js\.map$/)
60+
expect.stringMatching(/^my-shared-worker-\w+\.js\.map$/)
6361
)
6462
expect(files).toContainEqual(
65-
expect.stringMatching(/^possible-ts-output-worker\.\w+\.js\.map$/)
63+
expect.stringMatching(/^possible-ts-output-worker-\w+\.js\.map$/)
6664
)
6765
expect(files).toContainEqual(
68-
expect.stringMatching(/^worker-nested-worker\.\w+\.js\.map$/)
66+
expect.stringMatching(/^worker-nested-worker-\w+\.js\.map$/)
6967
)
7068
expect(files).toContainEqual(
71-
expect.stringMatching(/^sub-worker\.\w+\.js\.map$/)
69+
expect.stringMatching(/^sub-worker-\w+\.js\.map$/)
7270
)
7371

7472
// sourcemap should exist and have a data URL
75-
expect(indexSourcemap).toMatch(/^main-module\.\w+\.js\.map$/)
76-
expect(workerSourcemap).toMatch(/^my-worker\.\w+\.js\.map$/)
77-
expect(sharedWorkerSourcemap).toMatch(/^my-shared-worker\.\w+\.js\.map$/)
73+
expect(indexSourcemap).toMatch(/^main-module-\w+\.js\.map$/)
74+
expect(workerSourcemap).toMatch(/^my-worker-\w+\.js\.map$/)
75+
expect(sharedWorkerSourcemap).toMatch(/^my-shared-worker-\w+\.js\.map$/)
7876
expect(possibleTsOutputWorkerSourcemap).toMatch(
79-
/^possible-ts-output-worker\.\w+\.js\.map$/
77+
/^possible-ts-output-worker-\w+\.js\.map$/
8078
)
8179
expect(workerNestedWorkerSourcemap).toMatch(
82-
/^worker-nested-worker\.\w+\.js\.map$/
80+
/^worker-nested-worker-\w+\.js\.map$/
8381
)
84-
expect(subWorkerSourcemap).toMatch(/^sub-worker\.\w+\.js\.map$/)
82+
expect(subWorkerSourcemap).toMatch(/^sub-worker-\w+\.js\.map$/)
8583

8684
// worker should have all imports resolved and no exports
8785
expect(workerContent).not.toMatch(`import`)

‎playground/worker/vite.config-es.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module.exports = vite.defineConfig({
1414
plugins: [vueJsx()],
1515
rollupOptions: {
1616
output: {
17-
assetFileNames: 'assets/worker_asset.[name].[ext]',
18-
chunkFileNames: 'assets/worker_chunk.[name].js',
19-
entryFileNames: 'assets/worker_entry.[name].js'
17+
assetFileNames: 'assets/worker_asset-[name].[ext]',
18+
chunkFileNames: 'assets/worker_chunk-[name].js',
19+
entryFileNames: 'assets/worker_entry-[name].js'
2020
}
2121
}
2222
},

‎playground/worker/vite.config-iife.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = vite.defineConfig({
1919
worker: {
2020
rollupOptions: {
2121
output: {
22-
entryFileNames: 'assets/worker_entry.[name].js'
22+
entryFileNames: 'assets/worker_entry-[name].js'
2323
}
2424
}
2525
}
@@ -29,10 +29,10 @@ module.exports = vite.defineConfig({
2929
],
3030
rollupOptions: {
3131
output: {
32-
assetFileNames: 'assets/worker_asset.[name].[ext]',
33-
chunkFileNames: 'assets/worker_chunk.[name].js',
32+
assetFileNames: 'assets/worker_asset-[name].[ext]',
33+
chunkFileNames: 'assets/worker_chunk-[name].js',
3434
// should fix by config-test plugin
35-
entryFileNames: 'assets/worker_.[name].js'
35+
entryFileNames: 'assets/worker_-[name].js'
3636
}
3737
}
3838
},

‎playground/worker/vite.config-relative-base.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module.exports = vite.defineConfig({
1414
plugins: [vueJsx()],
1515
rollupOptions: {
1616
output: {
17-
assetFileNames: 'worker-assets/worker_asset.[name]-[hash].[ext]',
18-
chunkFileNames: 'worker-chunks/worker_chunk.[name]-[hash].js',
19-
entryFileNames: 'worker-entries/worker_entry.[name]-[hash].js'
17+
assetFileNames: 'worker-assets/worker_asset-[name]-[hash].[ext]',
18+
chunkFileNames: 'worker-chunks/worker_chunk-[name]-[hash].js',
19+
entryFileNames: 'worker-entries/worker_entry-[name]-[hash].js'
2020
}
2121
}
2222
},

‎playground/worker/vite.config-sourcemap.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ module.exports = vite.defineConfig((sourcemap) => {
2020
plugins: [vueJsx()],
2121
rollupOptions: {
2222
output: {
23-
assetFileNames: 'assets/[name].worker_asset[hash].[ext]',
24-
chunkFileNames: 'assets/[name].worker_chunk[hash].js',
25-
entryFileNames: 'assets/[name].worker_entry[hash].js'
23+
assetFileNames: 'assets/[name]-worker_asset[hash].[ext]',
24+
chunkFileNames: 'assets/[name]-worker_chunk[hash].js',
25+
entryFileNames: 'assets/[name]-worker_entry[hash].js'
2626
}
2727
}
2828
},
@@ -33,9 +33,9 @@ module.exports = vite.defineConfig((sourcemap) => {
3333
sourcemap: sourcemap,
3434
rollupOptions: {
3535
output: {
36-
assetFileNames: 'assets/[name].[hash].[ext]',
37-
chunkFileNames: 'assets/[name].[hash].js',
38-
entryFileNames: 'assets/[name].[hash].js'
36+
assetFileNames: 'assets/[name]-[hash].[ext]',
37+
chunkFileNames: 'assets/[name]-[hash].js',
38+
entryFileNames: 'assets/[name]-[hash].js'
3939
}
4040
}
4141
}

‎pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.