-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: convert HTMLNano to Es Modules #260
Conversation
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.
I am not a fan of pure ESM package, as well as the existing community. htmlnano is still used by toolchain/bundler that uses CommonJS. Would you like to make it a dual ESM/CJS?
If you notice, I have kept the package backwards compatible. The main entry still points to the In fact, I added some commonjs compatibility tests for that: |
Could you approve the CI? |
Sure. Just did. |
Thank you. This PR is ready. Let me know if there is anything else to be done here. |
@SukkaW what do you think, can it be merged now? |
This pull request is ready, but I made some changes to the Babel plugin responsible for silane/babel-plugin-replace-import-extension#9 Depending on the timing of the merges, I'll either update this PR or make a new PR to htmlnano with the improvement. |
This allows the external bundlers to work properly and optimize the imports
I published my fork of the Babel plugin to unblock us. Now, the dynamic imports can be processed by bundlers (e.g. for usage as an Astro plugin) and the Now, my astro-htmlnano plugin finally works: |
Thanks! @aminya I guess this could be released as a minor version or patch as it doesn't contain any backward incompatible changes? |
You are welcome! I'd go with a minor version as the addition is a new feature. But it should be backwards compatible. |
Fixes #259
This removes all the usage of commonjs from HTMLNano replacing it with standard ES modules. The optional dependencies are now imported using dynamic imports. So, the functionality will be preserved.
All the current tests pass. I added commonjs compatibility tests to make sure nothing breaks.
The minify function returned by htmlnano is now async due to the dynamic import.
posthtml
should await this promise. Based on the tests, posthtml already does this, so there should not be an issue.This change allows adoption of HTMLNano to new projects that only work with pure ES modules.
Tests passing:
Backwards compatibility tests: