preactjs / preset-vite

Preset for using Preact with the vite bundler
https://npm.im/@preact/preset-vite
MIT License
259 stars 26 forks source link

Add config to specify plugin-transform-react-jsx `throwIfNamespace` #102

Open CorruptedHeart opened 7 months ago

CorruptedHeart commented 7 months ago

It appears that specifying throwIfNamespace in a .babelrc file no longer causes it to apply to the @babel/plugin-transform-react-jsx or @babel/plugin-transform-react-jsx-development. Even if specifying babelrc: true as a config option.

This is to allow stuff like unocss attributify mode which supports attributes like disabled:bg-grey on elements.

Currently the only documented use case is throwIfNamespace.

rschristian commented 7 months ago

Couldn't you simply specify your own copy of the @babel/plugin-transform-react-jsx plugin with the necessary options?

CorruptedHeart commented 7 months ago

@rschristian due to the order of the spreads here: https://github.com/preactjs/preset-vite/blob/main/src/index.ts#L193-L202, it causes warnings about duplicate plugins.

Also, we'd be relying on the users to also care about stuff like isProduction, etc.

rschristian commented 7 months ago

In that case, perhaps we can detect if the user-provided plugins contains the jsx transform, and if so, replace the plugin config completely (rather than spread into it)?

Another config option is worst-case scenario, and doesn't seem fitting for a niche Babel option.

Also, we'd be relying on the users to also care about stuff like isProduction, etc.

Their config, their choice whether to care or not.