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.24k stars 287 forks source link

Transformer plugin for Nestjs/graphql cli plugin #783

Open Yehonal opened 3 years ago

Yehonal commented 3 years ago

Hello,

First of all, congratulation for this spectacular tool!

I'm using ncc together with nestjs, graphql and it's own transformer CLI plugin. I've been able to make it work by compiling NestJs first (with its own build command) and then running ncc on already-transpiled code.

However, if I want to do the entire process with ncc only (in order to have a better source-map) the transformer is not applied, therefore the app doesn't work because of missing graphql fields (that should have been generated by the plugin).

Is there a way to specify a transformer plugin with ncc?

styfle commented 3 years ago

You would have to modify ncc source code if you want to use different webpack loaders.

I haven't tried nest, but perhaps the generic solution is detecting the nest wrappers like we do for browserify/webpack/etc here https://github.com/vercel/webpack-asset-relocator-loader/blob/main/src/utils/wrappers.js

Yehonal commented 3 years ago

I think it's mostly related to ts-loader, I've noticed you are using ts-loader here: https://github.com/vercel/ncc/blob/main/src/loaders/ts-loader.js

Ts-loader offers the getCustomTransformer option: https://github.com/TypeStrong/ts-loader#getcustomtransformers

Maybe we just need to provide a way to set our custom transformer for the integrated ts-loader and it should work. What do you think?

styfle commented 3 years ago

We’ll probably replace ts-loader so we don’t want to expose any options there

Yehonal commented 3 years ago

The option for the transformer is available basically for all the typescript compilers (ts-loader, ts-node etc.) It should be easy to create a generic conf that can be applied to any tool you're going to use in future.

There are many typescript libraries out of there that use those transpiler plugins, without that option ncc is simply not usable with such TS libraries