chore: load or create svgo.config.js #10211
Draft
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.
Note: This is a draft! It does work, and all tests are passing, but I'm not very familiar with the repository and wary that I haven't handled loading files and applying them to the webpack configuration correctly. (Or if you're even ok with that approach!)
This is mostly intended to be a starting point, any feedback or mentorship would be appreciated! Once we're happy with the implementation and interface, I can introduce new tests and documentation.
Pre-flight checklist
Motivation
There have been discussions about introducing an easier way for users to configure SVGO. This is an attempt to expose it similarly to how SVGO itself and SVGR does.
svgo.config.js
(or.mjs
/.cjs
) file.svgo.config.js
file, though… based on the docs I don't know how. 😓This PR makes it so if a
svgo.config.js
file is present in the site directory, it loads it instead of using what Docusaurus defines. If it is not present, Docusaurus uses a default config which is the same as before.Changes
loadFreshModule
is no longer async as it never called await internally anyway, this allowed me to use it ingetFileLoaderUtils
without much fuss.svgo.config.js
to the generated filesgetFileLoaderUtils
, readssvgo.config.js
from generated files and passes that config to SVGO.Test Plan
Test links
Before
This is how the dogfooding page looked originally, and still looks when no
svgo.config.js
file is present. Docusaurus defines a default config if one isn't defined otherwise.After
I now created a
svgo.config.js
file with the following content:website/svgo.config.js
This is how the dogfooding page looks with the config applied. We load the config from the generated files, which is written to while building:
Deploy preview: https://deploy-preview-10211--docusaurus-2.netlify.app/tests/docs/tests/svgs/
Related issues/PRs
Edit: I also just noticed #9192. No promises, but I'll give it a peek and see if this is something I can handle in the near future.