Skip to content

Commit cc2adb3

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

File tree

34 files changed

+133
-139
lines changed

34 files changed

+133
-139
lines changed

package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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', () => {

0 commit comments

Comments
 (0)