feat: add browser conditional export - #2277
Conversation
Expose the browser bundle from the root `svgo` entry when a resolver enables the `browser` condition, retaining Node-specific `import` and `require` entries under `node` and `default`. Document resolution, the `svgo/browser` fallback, and TypeScript `customConditions: ["browser"]`. Add runtime export coverage and a browser-specific typecheck, run by the existing test and typecheck package.json scripts.
b006eeb to
5f13154
Compare
|
I've been thinking to unify entry points and stop bundling browser bundle. It would reduce install size quite a bit. Might do this by the next major bump. |
|
going esm-only would be great 👀 |
|
|
||
| // Add the browser condition to this import so Node resolves the browser branch | ||
| // of SVGO's root conditional export, just as a browser-targeting bundler would. | ||
| const hooks = registerHooks({ |
There was a problem hiding this comment.
Not very convinced about this test, since it is assuming something about how the bundler works internally, rather than testing a real bundler.
I did not notice both entry points were bundles. I think the change in this PR should be backward compatible, but I understand you might want to wait for a major before changing entry points, with all the build setups in the wild you never know when something might break.
One thing I have been wondering for some time is if it would be possible for users to use their own CSS minifier instead of CSSO (using an optional dependency somehow?). |
Hello, for some time, I had been struggling to bundle postcss-plugin-svgo for the browser without overriding the svgo dependency in the bundler config. This change should hopefully allow to run modules that depend on svgo on the browser and on node without overrides. One issue could be if someone wants to force the Node build for a browser build. In that case with this change they probably would need to change their bundler configuration. So for bundler users it could be seen as either a fix or a breaking change. But I don't think the Node.js functionality would ever work in the browser, so if they were bundling the Node.js versions it was likely a mistake.
Expose the browser bundle from the root
svgoentry when a resolver enables thebrowsercondition, retaining Node-specificimportandrequireentries undernodeanddefault.Document resolution, the
svgo/browserfallback, and TypeScriptcustomConditions: ["browser"].Add runtime export coverage and a browser-specific typecheck, run by the existing test and typecheck package.json scripts.