Support preserving assets input structure in the output#3069
Conversation
🦋 Changeset detectedLatest commit: 9105501 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| assetInCss.ref = ref; | ||
| assetInCss.outputPath = this.getFileName(ref); | ||
| if (!extractAssetsLegacyCss) { | ||
| assetInCss.hash = create64() |
There was a problem hiding this comment.
can't we just use node:crypto? it would achieve the same goal right? its not entirely clear to me why we need a dep to create the hash
There was a problem hiding this comment.
@thepassle xxhash is super fast, it's used by rollup internally too (although they made their own bindings for Rust functions) and recommended for non-crypto hashes in such use-cases
| * @param {string|string[]} [options.exclude] A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored. | ||
| * @param {boolean} [options.warnOnError] By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched. | ||
| * @param {function} [options.transform] A function to transform assets. | ||
| * @param {boolean} [options.preserveDynamicStructure] When enabled, emits dynamic assets and rewrites the URL pattern to resolve the original dynamic path relative to the first emitted asset. Requires that the output preserves both filenames (no hashing) and directory structure from the dynamic expression onwards. |
There was a problem hiding this comment.
@thepassle do you think preserveDynamicStructure is a suitable name given the behavior and purpose?
What I did
preserveDynamicStructureto@web/rollup-plugin-import-meta-assetsto resolve dynamic paths differently by using first asset as a base and preserving the dynamic part in the URL@web/rollup-plugin-htmlso that same use-case as inpreserveDynamicStructureis also supported (but it doesn't need any extra option since all paths are static and dynamic paths and dynamic runtime were not an issue)so that
assetFileNamescan preserve input structure of assets and no extra overhead is needed (e.g. no dynamic runtime in JS)Review pointers:
rollup-plugin-import-meta-assets
describe('preserveDynamicStructure', () => {is newpreserveDynamicStructurepreserveDynamicStructureuse-case without the option, but the idea was that we don't want the dynamic runtime with path maps, so the main reason to introduce this option is to prevent that runtime from being generatedrollup-plugin-html
describe('preserved output paths', () => {preserved output pathsis not correct at this point and the CSS content still might change, so in theory there is a possibility for bugs here, but in practice it needs to be a super weirdassetFileNamesconfiguration that can possibly result in such bug, I wasn't able to create a logical unit test for it (it must be some combination of using hash for CSS file names, but not assets, and then chanign output paths for some assets conditionally inassetFileNames, I can't possible imagine who would ever do that), so decided to stop chasing it