Declaration generated in wrong folder when using object as `input` (multi-entry)
See original GitHub issueWhat happens and why it is wrong
Possibly this is a misconfiguration on my end, but it looks like a bug. When you use an object
as the input
property for the rollup configuration, the typings file for the input files are generated in the root folder of the repo (same folder as the rollup config file) and not the target output directory (here, ./dist
) along with the bundled JS file.
Versions
- typescript: 3.2.4
- rollup: 1.1.2
- rollup-plugin-typescript2: 0.19.2
rollup.config.js
{
...
input: {
Lib1: './src/Lib1.tsx',
Lib2: './src/Lib2.tsx'
},
output: {
dir: './dist',
format: 'cjs',
sourcemap: true,
entryFileNames: '[name].js'
}
}
tsconfig.json
{
...
"compilerOptions": {
"outDir": "./dist"
},
}
Result:
// These files are created
./Lib1.d.ts
./Lib2.d.ts
// instead of (expected):
./dist/Lib1.d.ts
./dist/Lib2.d.ts
Curiously, if you enter entryFileNames: 'dist/[name].js'
it creates a superfluous subfolder called dist
within the dist
folder and creates them there.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:35 (11 by maintainers)
Top Results From Across the Web
makefile - How to place object files in separate subdirectory
Since you're using GNUmake, use a pattern rule for compiling object files: $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<.
Read more >rollup.js
rollup function receives an input options object as parameter and returns a Promise that resolves to a bundle object with various properties and...
Read more >API - esbuild
Passing esbuild multiple input files with bundling enabled will create multiple separate bundles instead of joining the input files together.
Read more >Using Dagger in Android apps
To inject an object in the activity, you'd use the appComponent defined in your Application class and call the inject() method, passing in...
Read more >Object Oriented Programming Using C# .NET - C# Corner
Once a class has been written, created and debugged, it can be distributed to other programmers for use in their own program. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup. that seems to be the only way unless you let
tsc
do the bundling end-to-end. These rollup plugins seem to be effecively asking tsc to do two different tasks:The results of 1 and 2 don’t, and can’t match when you’re using an “input map” and code-splitting, etc. – AFAICT.
…unless you make the rollup plugin a whole lot more involved in the type-declaration generation process.
For any struggling soul out there that has the same src folder structure as @maranomynet and me.
I came across a quick fix for it, may be another ugly way but works for me.
I’m using rollup-plugin/typescript2 so I’ll go with its config in this answer: Define your own declarationDir in your tsconfig.json so your project can dump all *.d.ts files in its own path in the bundled dist. And make sure to set the useTsConfigDeclarationDir to true in your typescript plugin in rollup config file. Also, where you define the output paths for your individual component bundles in your rollup.config.js (and package.json), change those paths to be the same as your ‘declarationDir’ + ‘how your src component route is’. So if your component in src is like:
And your declarationDir is:
So your output path needs to be like:
This way, rollup will include your types in the same directory as your component main.js and your TS consumer project will pick up the typings.
So the bundle will look something like: