feat(cli): add --placeholder and --select-* flags - #30
Merged
Conversation
Everything a value can express is an argument now, so a run needs no config file: `--placeholder`, `--placeholder-width` and `--placeholder-format` shape the placeholder export, and `--select-id`, `--select-format` and `--select-width` pick the variant the default export points at. A width or a format switches the placeholder on by itself, and `--no-placeholder` turns off one enabled in the config. The config file stays necessary for what an argument cannot carry: more than one rule, and the options that are functions or nested objects.
Coverage Report for CI Build 33515237877Coverage increased (+0.2%) to 93.871%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The placeholder and the module's default export could only be configured from
srcset.config.js. They are arguments now, so a run needs no config file at all:srcset "src/images/**/*.jpg" -d src/baked --module ts -w 1,0.5 -f jpg,webp \ --placeholder --placeholder-width 24 --select-format webp--placeholderplaceholderexport.--no-placeholderswitches off one enabled in the config.--placeholder-width,--placeholder-formatwebpby default,webporjpg. Either one implies--placeholder.--select-id,--select-format,--select-widthAn unknown placeholder format is rejected the way
--moduleis:Unknown placeholder format: "png". Use webp or jpg.args.tsstays a plain argv reader — the assembly and the validation live intoCliOptions, next totoModuleFormat, which is where the merge with the config file happens. Likerules, the arguments replace the config value rather than merging into it.What still needs a config file
Only what an argument cannot carry: more than one rule, and the options that are functions or nested objects —
resourceId,optimization,processing, andpostfixas a formatter. A stringpostfixis deliberately left out: it is applied verbatim to every variant, so with several widths they would all resolve to one output path and the run would stop on the collision guard.Verified end to end:
--placeholderemits a webp data-url,--placeholder-width 8 --placeholder-format jpga jpeg one,--select-format webpmakes the module'surlthe webp variant, and--no-placeholderbeatsplaceholder: truefrom the config. The cli suite goes from 46 to 56.