mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix(legacy)!: should rename x.[hash].js
to x-legacy.[hash].js
(#11599)
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
parent
a2e9fb5243
commit
e7d7a6f4ee
@ -337,6 +337,11 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
|
||||
if (fileName.includes('[name]')) {
|
||||
// [name]-[hash].[format] -> [name]-legacy-[hash].[format]
|
||||
fileName = fileName.replace('[name]', '[name]-legacy')
|
||||
} else if (fileName.includes('[hash]')) {
|
||||
// custom[hash].[format] -> [name]-legacy[hash].[format]
|
||||
// custom-[hash].[format] -> [name]-legacy-[hash].[format]
|
||||
// custom.[hash].[format] -> [name]-legacy.[hash].[format]
|
||||
fileName = fileName.replace(/[.-]?\[hash\]/, '-legacy$&')
|
||||
} else {
|
||||
// entry.js -> entry-legacy.js
|
||||
fileName = fileName.replace(/(.+)\.(.+)/, '$1-legacy.$2')
|
||||
|
@ -97,6 +97,13 @@ describe.runIf(isBuild)('build', () => {
|
||||
expect(manifest['../../vite/legacy-polyfills-legacy'].src).toBe(
|
||||
'../../vite/legacy-polyfills-legacy',
|
||||
)
|
||||
expect(manifest['custom0-legacy.js'].file).toMatch(
|
||||
/chunk-X-legacy.\w{8}.js/,
|
||||
)
|
||||
expect(manifest['custom1-legacy.js'].file).toMatch(
|
||||
/chunk-X-legacy-\w{8}.js/,
|
||||
)
|
||||
expect(manifest['custom2-legacy.js'].file).toMatch(/chunk-X-legacy\w{8}.js/)
|
||||
// modern polyfill
|
||||
expect(manifest['../../vite/legacy-polyfills']).toBeDefined()
|
||||
expect(manifest['../../vite/legacy-polyfills'].src).toBe(
|
||||
|
1
playground/legacy/custom0.js
Normal file
1
playground/legacy/custom0.js
Normal file
@ -0,0 +1 @@
|
||||
export const foo = 'bar'
|
1
playground/legacy/custom1.js
Normal file
1
playground/legacy/custom1.js
Normal file
@ -0,0 +1 @@
|
||||
export const foo = 'bar'
|
1
playground/legacy/custom2.js
Normal file
1
playground/legacy/custom2.js
Normal file
@ -0,0 +1 @@
|
||||
export const foo = 'bar'
|
@ -3,6 +3,9 @@ import viteSvgPath from './vite.svg'
|
||||
import MyWorker from './worker?worker'
|
||||
|
||||
async function run() {
|
||||
await import('./custom0.js')
|
||||
await import('./custom1.js')
|
||||
await import('./custom2.js')
|
||||
const { fn } = await import('./async.js')
|
||||
fn()
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ export default defineConfig({
|
||||
chunkFileNames(chunkInfo) {
|
||||
if (chunkInfo.name === 'immutable-chunk') {
|
||||
return `assets/${chunkInfo.name}.js`
|
||||
} else if (/custom\d/.test(chunkInfo.name)) {
|
||||
return `assets/chunk-X${
|
||||
['.', '-', ''][/custom(\d)/.exec(chunkInfo.name)[1]]
|
||||
}[hash].js`
|
||||
}
|
||||
return `assets/chunk-[name].[hash].js`
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user