microbundle icon indicating copy to clipboard operation
microbundle copied to clipboard

[Feature Request] use ttypescript under the hood to enable applying TS transforms

Open quantizor opened this issue 4 years ago • 9 comments

https://www.npmjs.com/package/ttypescript

The main benefit of going with this solution is being able to specify transformer plugins in tsconfig.json so it's an easy configuration

quantizor avatar Sep 07 '20 02:09 quantizor

~~Nvm, I see you're using https://github.com/ezolenko/rollup-plugin-typescript2. Will move the FR there.~~

update: it's actually meant to be passed as a transform to rollup-plugin-typescript2 https://www.npmjs.com/package/ttypescript#rollup

quantizor avatar Sep 07 '20 02:09 quantizor

First of all, thank you for opening a PR. Can you elaborate a little bit on why we want to allow typescript transformers? Why not go for a babel plugin?

I'm worried that if we swap typescript with a third party compiler, we will open up to more bugs that are not related to microbundle itself.

wardpeet avatar Sep 07 '20 07:09 wardpeet

I actually tried using a relevant Babel plugin but it didn’t seem to work, possibly because of the order of tools? Not quite sure.

For example, I wanted to run the styled-components Babel plugin over some code but adding it to babelrc had no effect.

quantizor avatar Sep 07 '20 12:09 quantizor

I would also be in favor of including ttypescript so that I can use https://www.npmjs.com/package/ts-transformer-properties-rename to rename TS properties.

berndartmueller avatar Sep 08 '20 13:09 berndartmueller

@wardpeet

from https://github.com/cevek/ttypescript#what-it-is:

Instead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.

No version lock-ins - typescript used as peer dependency.

ttypescript uses typescript under the hood. I don't BELEIVE anything should break. However, smoke tests should be written if no one else is certain.

waynevanson avatar Sep 14 '20 11:09 waynevanson

Yeah it basically just allows the rollup plugin to also look at tsconfig.json :)

quantizor avatar Sep 14 '20 16:09 quantizor

FWIW @berndartmueller Microbundle already provides that exact feature:

// package.json
{
  "mangle": {
    "properties": "^_"
  }
}

developit avatar Nov 05 '20 18:11 developit

@developit I think ts-transformer-properties-rename can do even more - it automatically detects what properties are "public" (or "external") and don't rename them, and what properties are internal (not just "private" in terms of class methods/properties, but all objects fields which aren't public/external) and rename them accordingly.

I'd say ts-transformer-properties-rename should be used before properties mangling, because the transformer does not minify them, just add a prefix to name so it's still easy to debug but could be well minified with properties mangling.

timocov avatar Nov 13 '20 22:11 timocov

Maybe instead of hardcoding it to ttypescript, make a new cli option like --typescript-compiler (or --tsc?)? Then it's opt-in, so if it breaks things people know it's probably not microbundle.

Js-Brecht avatar Mar 14 '21 21:03 Js-Brecht