wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc
MIT License
496 stars 32 forks source link

Is the `configPlugin` CLI option supported? #180

Closed roydukkey closed 2 years ago

roydukkey commented 2 years ago

Question

I was trying to figure out if I could write my rollup.config.js using typescript and notices that rollup defines the --configPlugin option for the CLI to achieve this.

rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript

However, I'm obviously not using the @rollup/plugin-typescript to rollup my typescript project. 😁 So, I thought I'd just set this plugin as the CLI option.

rollup --config ./rollup.config.ts --configPlugin rollup-plugin-ts

This does work! But, I just wanted to check that this is officially supported?

roydukkey commented 2 years ago

Ooo. It worked until I tried to import the package.json and gave the following error message even though I had the configuration is my tsconfig.json.

% yarn workspace @sass-fairy/exception build
yarn workspace v1.22.18
yarn run v1.22.18
$ rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts
[!] (plugin Typescript) TS2732: Cannot find module './package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
../../rollup.config.ts (9:36)

9 import { author, repository } from './package.json';

Note: my ../../tsconfig.json up two levels as well, since I'm working on a project using workspaces.


I imagine this would be rollup's proposed remedy, and it works.

It supports the same syntax as the --plugin option i.e., [...] and you can specify plugin options via ={...}.

rollup --config ../../rollup.config.ts --configPlugin 'rollup-plugin-ts={tsconfig:`../../tsconfig.json`}'
wessberg commented 2 years ago

Haha, pretty awesome that it worked out of the box. But I guess there's no reason why it wouldn't! I hadn't actually heard of that feature, I'm definitely going to use that one myself. Thanks for the tip. As for the error you ran into, to me it sounds like what you're experiencing here is that @rollup/plugin-typescript might discover the tsconfig you're having a few folders up in your file system automatically by traversing the files system, whereas rollup-plugin-ts doesn't, as it only looks for a tsconfig.json adjacent to to rollup config in the current working directory.