mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
feat(legacy): build file name optimization (#15115)
This commit is contained in:
parent
26a613a277
commit
39f435d8ce
@ -119,6 +119,9 @@ const legacyEnvVarMarker = `__VITE_IS_LEGACY__`
|
||||
|
||||
const _require = createRequire(import.meta.url)
|
||||
|
||||
const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/
|
||||
const prefixedHashInFileNameRE = /[.-]?\[hash(:\d+)?\]/
|
||||
|
||||
function viteLegacyPlugin(options: Options = {}): Plugin[] {
|
||||
let config: ResolvedConfig
|
||||
let targets: Options['targets']
|
||||
@ -337,11 +340,12 @@ 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]')) {
|
||||
} else if (nonLeadingHashInFileNameRE.test(fileName)) {
|
||||
// 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$&')
|
||||
// custom.[hash:10].[format] -> custom-legacy.[hash:10].[format]
|
||||
fileName = fileName.replace(prefixedHashInFileNameRE, '-legacy$&')
|
||||
} else {
|
||||
// entry.js -> entry-legacy.js
|
||||
// entry.min.js -> entry-legacy.min.js
|
||||
|
Loading…
Reference in New Issue
Block a user