vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.27k stars 291 forks source link

Support Babel (v7+) #215

Open tunnckoCore opened 5 years ago

tunnckoCore commented 5 years ago

So we'll be able to support the other variant of using TypeScript through Babel.

Because, currently if you use Jest... and especially, as @kentcdodds said few times, if you don't want to give up the javascript ecosystem, you'll end up wanting to use the JS tooling as much as possible. So if you plan to use Jest with babel-jest and so TypeScript through Babel 7, then your tests and what not will use Babel, but when you building the final "dist" you will end up with Webpack + TSC (the ncc).

The thing is that when you use TypeScript through Babel, you should not care about the targets option from tsconfig, right? Because you usually will use the @babel/preset-env so it will decide to what will be compiled down to. I really still struggling to remember those TS options and actually don't want to care and trust on TS ecosystem when (and as much as) possible.

For example.

  "browserslist": [
    "node 8",
    "node 10",
    "not dead",
    ">= 1%",
    "last 2 Opera versions"
  ],
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "useBuiltIns": "usage"
        }
      ],
      "@babel/preset-react",
      "@babel/preset-typescript"
    ]
  },

In the tests Jest will use this config, which will (and should) ignore (i guess) what (and if) you set on the targets on the tsconfig right? Okey, but once you are ready to deploy/publish and use ncc build it will resolve the tsconfig and so it will either use what you set as targets there, or it will default to who knows what (ooor it will fail? i'm ot usre if this option is required).

Generally speaking, I never wanted to trust TypeScript and Microsoft. And that's not so religious thing. But really seeing and feeling the power on that train, and TypeScript is great. The thing is that integrations with it is hard or at least you should be careful how and what you are doing.

It's mess. :D But that's the fun part.

3cp commented 4 years ago

If ncc adds an option to write to standard output (throw if it cannot confine the output to a single file), at least we can pipe the output to babel cli.