jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.24k stars 506 forks source link

Allow targeting of specific file extensions for babel rollup plugin #656

Open kylemh opened 4 years ago

kylemh commented 4 years ago

Current Behavior

I'm unable to customize the targeted file extensions for plugins and don't have an easy way to ignore one plugin and extend it how I want it. I need to do so to resolve this issue since I need to have babel run across .svg files to avoid bugs in Edge for my icon library.

Desired Behavior

Allow me to determine the file extensions targeted by each rollup plugin.

kylemh commented 4 years ago

As an aside... I just realized I've been shipping ESM to all my applications without bundling the dependency. This library I'm making is being used in multiple apps with the same transpile target... Is there a way for me to get the code-splitting ESM provides, while also getting uglified and minified named modules?

agilgur5 commented 4 years ago

Sorry I didn't respond earlier, needed to be at my computer so I could add links and easier and this one's gonna be backlogged anyway unfortunately.

Basically I don't think it makes sense to add a specific feature for this, but I've been planning (and at some point Jared did too, c.f. https://github.com/jaredpalmer/tsdx/issues/389#issuecomment-568785862) on opening up the Rollup config since a bit before #389 so that anyone can more easily override any plugin's config as necessary. More concretely, that would be something like a deep merge or new functions added in tsdx.config.js, one for each plugin.

That would support this and a variety of things as a generic case, without adding the maintenance cost of a specific feature for this very specific use-case. So this effectively duplicates #389 in that sense, and in the meantime, I'd suggest a similar fix as there, using patch-package for your needs or a really hacky tsdx.config.js override with the current set-up.

Also related to #635

agilgur5 commented 4 years ago

As an aside... I just realized I've been shipping ESM to all my applications without bundling the dependency. This library I'm making is being used in multiple apps with the same transpile target... Is there a way for me to get the code-splitting ESM provides, while also getting uglified and minified named modules?

So your bundler (e.g. webpack) will minify any ESM packages during its build process, so this isn't really an issue. There's no way to conditionally switch between a dev or prod bundle in ESM (like TSDX does with CJS), so TSDX leaves that to your bundler. If you want to produce a minified, production-only ESM build, you can follow https://github.com/jaredpalmer/tsdx/issues/631#issuecomment-602131471, noting all the caveats there-in (unofficial/incidental support, no package.json field for it, etc).