Skip to content

feat: add browser conditional export - #2277

Open
ludofischer wants to merge 2 commits into
svg:mainfrom
ludofischer:browser-entrypoint
Open

feat: add browser conditional export#2277
ludofischer wants to merge 2 commits into
svg:mainfrom
ludofischer:browser-entrypoint

Conversation

@ludofischer

Copy link
Copy Markdown
Contributor

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 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.

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.
@ludofischer
ludofischer marked this pull request as draft August 24, 2026 12:04
@ludofischer
ludofischer marked this pull request as ready for review August 24, 2026 12:18
@TrySound

Copy link
Copy Markdown
Member

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.

@gameroman

Copy link
Copy Markdown

going esm-only would be great 👀

Comment thread test/exports.js

// 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({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very convinced about this test, since it is assuming something about how the bundler works internally, rather than testing a real bundler.

@ludofischer

Copy link
Copy Markdown
Contributor Author

I've been thinking to unify entry points and stop bundling browser bundle.

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.

It would reduce install size quite a bit.

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?).

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.

3 participants