-
-
Notifications
You must be signed in to change notification settings - Fork 613
Description
- Rollup Plugin Name: typescript
- Rollup Plugin Version: @rollup/plugin-typescript": "^8.1.0",
Feature Use Case
I would like to bundle a typescript file including only its source code and referenced imports, without implicitly transpiling every typescript file contained in the longest common root folder of the file and its imports, which seems to be the current behaviour.
The repository at https://github.com/cefn/testcase_rollup was constructed to clarify the problem. Having failed to find any configuration parameter which allows compiling of just a file and its imports, I'm raising it as a feature request.
A shortcut to the rollup script in the repo is...
https://github.com/cefn/testcase_rollup/blob/main/test_rollup.ts
It is intended to compile prefix.ts to a bundle called prefix.js
Feature Proposal
A configuration option to the Rollup plugin should be added, which makes it implicitly define the include tsconfig parameter, setting it to match the paths of the imported files it is about to bundle (only the file and its imports recursively).
Setting the include to be only these files would prevent typescript from implicitly transpiling everything in the whole project just to bundle a single file.
Background
Currently there are two successful ways to compile the source shown as A) and B) below. They are both problematic. This feature would provide a third case, benefiting from rollup's own modelling of recursive imports to construct a sensible list for include.
- A) Explicitly construct an
includelist with all *.ts files which are imported before running rollup.- Problem: the developer has to inspect and list the recursive imports of a file to bundle it. Leaving anything out means a failure to compile. You can see the list I calculated for prefix.ts which has to be declared here. Omitting anything means prefix.ts fails to compile.
- This defeats the purpose. I am effectively building my own bundling library. If I already know the file path and all of its imports then could just use typescript transpile and string-concatenation to construct the bundle.
- B) Omit
include(to achieve this I comment the parameter in the repro example here)- Problem: rollup attempts to transpile all files in the whole project
- I believe in the case of the repro
rootDirbecomes implicitly the longest common path of mapreduce.js and prefix.js (which is the project root folder) andincludeis implicitly "*/.ts". Hence rollup transpiles all project files, including the bundling routine itself!