Skip to content
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

Merged
merged 11 commits into from Sep 23, 2021
Merged

Support es modules #1583

merged 11 commits into from Sep 23, 2021

Conversation

TrySound
Copy link
Member

Ref #1579

In config of course. Projects with type:module can now use modules to
export config

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

cc @ai

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
@TrySound
Copy link
Member Author

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));
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

@omgovich omgovich left a 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.

@TrySound TrySound merged commit 7111c52 into master Sep 23, 2021
@TrySound TrySound deleted the esm-support branch September 23, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants