svgo: CLI option to disable plugins is no longer available
I used an old version of SVGO like e.g. comand
svgo -i input.svg -o output.svg --pretty --indent=1 -p 3 --enable=removeHiddenElems --disable=removeUnknownsAndDefaults
and I got error: unknown option '--enable=removeHiddenElems'
However it seems svgo is not backwards compatible.
I have read #1329 and #1337/files, and do not understand what to do.
I have tried to copy svgo.config.js from https://github.com/svg/svgo/issues/1329#issuecomment-781585374 into the current folder and got
Error: Cannot find module 'svgo'
Require stack:
- /home/jkalliau/Documents/GitHub/cleanupSVG/svgo.config.js
- /home/jkalliau/prgm/node-v15.4.0-linux-x64/lib/node_modules/svgo/lib/svgo-node.js
- /home/jkalliau/prgm/node-v15.4.0-linux-x64/lib/node_modules/svgo/lib/svgo/coa.js
- /home/jkalliau/prgm/node-v15.4.0-linux-x64/lib/node_modules/svgo/bin/svgo
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/home/jkalliau/Documents/GitHub/cleanupSVG/svgo.config.js:3:34)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- feat: add support for `--disable` and `--enable` flags back Closes #1356 Closes #1622 In https://github.com/svg/svgo/issues/1622#issuecomment-971440346 we read: > I consider adding it back at some ... — committed to wojtekmaj/svgo by wojtekmaj 3 years ago
- feat: add support for `--disable` and `--enable` flags back Closes #1356 Closes #1622 In https://github.com/svg/svgo/issues/1622#issuecomment-971440346 we read: > I consider adding it back at some ... — committed to wojtekmaj/svgo by wojtekmaj 3 years ago
Came here for a similar reason: after my weekly update I had a lot of CI builds failing with
error: unknown option '--disable=removeViewBox'.The releases notes for 2.0.0 suggests that
--disable/--enablemight be reimplemented in a later version, so I’ll simply stick to svgo@1.3.2 in the meantime. The amount of configuration needed in 2.0.0 to simply disable one plugin seems a bit overkill in my case.I would like the reimplementation of
--enable=PLUGIN-feature. (maybe I switch back to the buggy 1.3.2-version)I had closed the issue, since I was able to solve the error, not meaning I’m anyhow happy with the solution/workaround.
Imho this bug-report/question is solved, but we should file a new feature-request. Since I do not know any duplicate/feature-request I reopen this issue for now, however it is up to the svgo-mebers how to proceed.
Only possible with config for now
Let me preface this by saying I do admire and appreciate the team’s decision to, as a
wisefamous man once said: “Move Fast and Break Things”However… I, too, was just bitten by the removal of the
--enable=PLUGINCLI argument. 😦I would vote that this issue be reopened, lest people inadvertently start creating duplicates. (I almost did!)
Hi. You need to install svgo locally like this
npm i svgoIn an attempt to turn this conversation back from “You’re Reading The Documentation Wrong” to “
--enableand--disableFlags Are *Way* More Convenient Than Config Files For Ad-Hoc Workflows” I offer the followinggross hack_*clever*_wrapper_script_ [N.B., “clever” is *not* a compliment, when it comes to software… «grin»]prompt% less ~/bin/svgo.shPS — Yadita yadita, “No warranties, no copyrights, and no ifs, ands, or buts…” etc. ;-D
If it’s helps, SVGO no longer needs to be installed in the local scope. Doing
npm i -g svgo/yarn global add svgois fine. As for configuring SVGO, currently the recommended way is to create ansvgo.config.mjswith a default export like:Then, if it’s in the same directory, use SVGO as normal and it will detect the file. Or if it’s the config file is stored elsewhere, reference the config file with the
--configargument.This means:
node_modules.If this isn’t desirable, I’d still be reluctant to bring back
--enableand--disablebecause I don’t think it makes sense with how SVGO is designed today. There aren’t obvious expectations on how enabling plugins would work.default-preset? Or operate as well asdefault-preset?default-preset, will we ignore it, or run it twice, once as part ofdefault-presetand then again afterward?preset-default?--enableor--disablewere specified, then we’d skip seeking ansvgo.config.mjsfile, or would you want--disableto still use thesvgo.config.mjsfile but without the specified plugin?While we could define these things, I prefer how unambiguous and unassuming the current configuration is. SVGO config is more like a pipeline, and pipelines aren’t simply configured by turning things on or off. Things like order and options matter.
I would however be willing to add an argument like
--pluginsthat allows one to specify thepluginsproperty as it would be defined insvgo.config.mjs, but in the CLI without having to create a file on disk. We already have a CLI option for most of the options present insvgo.config.mjsanyway, just not one to define thepluginsproperty. As for precedence, the explicit CLI option (--plugin) would take priority over whatever is defined insvgo.config.mjs(plugins), similarly to the behavior we already have for all other options.Examples:
Disabling a plugin is a little verbose, but otherwise:
svgo.config.mjs, so this should be intuitive enough to use.--enable. (However, still no JavaScript functions or custom plugins.)How would the participants of this issue feel about that?
Came here because of this as well. Looks like there is no way to use
svgoif I just want to use it as a CLI program (without e.g. polluting local scope withnode_modulescreated fromnpm i svgo). It’s probably better to remove CLI usage at all then as it’s so limited now.