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
Support es modules #1583
Support es modules #1583
Conversation
Ref #1579 In config of course. Projects with type:module can now use modules to export config ```js export default { plugins: [] } ``` Also added support for resolving svgo.config.mjs and svgo.config.cjs. Moved loadConfig tests to svgo-node tests. mjs test is skipped for now in node 10, just don't use modules there
Wow, worked! |
try { | ||
// dynamic import expects file url instead of path and may fail | ||
// when windows path is provided | ||
const { default: imported } = await import(pathToFileURL(configFile)); |
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.
Just a comment here: ESM can be imported using dynamic import without any more work to get it working?
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.
With current lts yes. But we still supported node 10 until next major release so we fallback to require in case of error.
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.
Looks great to me!
Smart! 👨🔬 I haven't considered this kind of fallback.
Ref #1579
In config of course. Projects with type:module can now use modules to
export config
Also added support for resolving svgo.config.mjs and svgo.config.cjs.
Moved loadConfig tests to svgo-node tests.
mjs test is skipped for now in node 10, just don't use modules there
cc @ai