-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(legacy): build file name optimization #15115
Changes from 8 commits
1b50187
8ee38dd
4ab2036
edad9b8
e19c550
bdaf9e3
735fdeb
61fa777
ee3f5f6
596f6a0
e181f62
97ce1d8
a8ffc30
2a99167
a2e47fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,24 +331,30 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { | |
} | ||
|
||
return (chunkInfo) => { | ||
let fileName = | ||
const file = | ||
typeof fileNames === 'function' ? fileNames(chunkInfo) : fileNames | ||
const fileArr = file.split('/') | ||
let fileName = fileArr.pop()! | ||
|
||
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$&') | ||
jiadesen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
// entry.js -> entry-legacy.js | ||
// entry.min.js -> entry-legacy.min.js | ||
fileName = fileName.replace(/(.+?)\.(.+)/, '$1-legacy.$2') | ||
if (fileName.includes('[hash]') && !fileName.startsWith('[hash]')) { | ||
sapphi-red marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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$&') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should support other separators here (using |
||
} else { | ||
// entry.js -> entry-legacy.js | ||
// entry.min.js -> entry-legacy.min.js | ||
// [hash].[format] -> [hash]-legacy.[format] | ||
// [hash]custom.[format] -> [hash]custom-legacy.[format] | ||
fileName = fileName.replace(/(.+?)\.(.+)/, '$1-legacy.$2') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was proposing we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that doesn't happen because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah... then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, shouldn't we consider not adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user set it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is about not showing any info about the filename, then it doesn't hurt to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are going further, I think it would be better to make users possible to pass the names like |
||
} | ||
} | ||
|
||
return fileName | ||
return [...fileArr, fileName].join('/') | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading rollup docs, they only mention forward slashes, so I think this should be good and a user passing windows style paths here is not supported https://rollupjs.org/configuration-options/#output-assetfilenames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to only apply the conversion to the file part? I guess
/foo/[name]/[hash].[ext]
is valid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... I totally overlooked that. Thanks for reviewing this sapphi. I guess we need to go with something like I had at #15115 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although rollup allows this use, there is no mention of this usage in all related documentation and the default values of the properties, and these placeholders: [name], [hash], [ext], [extname] are strictly speaking only can be used for the final file name.