Plugins: Honor declaration config

Created on 19 Jul 2016  ·  17Comments  ·  Source: rollup/plugins

It would be nice if the declaration: true flag would be honored in the output.

s² 🔥🔥 important t³ ✨ enhancement x⁴ ⋅ hold 🔌 plugin-typescript

Most helpful comment

I've had to switch to rollup-plugin-typescript2 as well. Honestly, I don't see how this plugin is useful in for creating public packages without this feature.

All 17 comments

:+1:

:+1: I currently have to use typescript on its own to generate es6 files and .d.ts files and then use rollup for bundling and generating a UMD dist.

rollup-plugin-typescript2 says that it supports it. I will give it a try but I would prefer to use the official rollup plugin for typescript.

I've had to switch to rollup-plugin-typescript2 as well. Honestly, I don't see how this plugin is useful in for creating public packages without this feature.

Still no update on this? I have to sadly agree to @ncphillips ...

Yup, I've moved to rollup-plugin-typescript2 as well. Any idea on a timeline of when this will be implemented?

Guys, still nothing?

Had to switch to rollup-plugin-typescript2 too, and it's 10 times slower. Hope this is going to be fixed soon!

I use tsc --emitDeclarationOnly in addition to rollup. It‘s not that bad, but it‘s also not perfect.

There are quite a few people commenting on support for this, but we don't have any open PRs to address this. We're _totally_ open to adding this, but we need you fine folks to help us. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one if no one from userland steps up to make the request happen. After that point, we'd encourage anyone still facing the issue to pitch in on the new repo and get this improvement in for the plugin.

Hey folks. We're in progress on migrating the plugin, and have transferred this issue. We're going to lock it for a short time until the migration is complete, and then we'll unlock and continue the discussion. 🍺

Is anybody working on this?

Yes, it's being worked on. Contributor support is also welcome!

Added in version 4.0.0 of the typescript plugin

For others also potentially struggling with this: For types to be emitted, you currently have to declare a rootDir in tsconfig.json. This is related to https://github.com/rollup/plugins/issues/243. Even though the compilation does not fail when using declarationDir instead of outDir this does also apply when using declarationDir.

Also have a look at the PR that implemented this feature for instructions on how to generate declaration files: https://github.com/rollup/plugins/pull/217

Thanks @danimoh it's very helpful. additionally..

  • output.dir is required for declaration: true option.
  • declarationDir folder should be inside output.dir.
  • do not use declaration and declarationDir in tsconfig.json. declarationDir can't override using @rollup/plugin-typescript

Here's my rollup config to make redux style outputs.

import typescript from '@rollup/plugin-typescript'

export default [
  // CommonJS
  {
    input: 'src/index.ts',
    output: {
      dir: './',
      entryFileNames: 'lib/my-pkg.js',
      format: 'cjs',
    },
    plugins: [
      typescript({
        declaration: true,
        declarationDir: 'types/',
        rootDir: 'src/'
      }),
    ]
  },

  // ES
  {
    input: 'src/index.ts',
    output: { file: 'es/my-pkg.js', format: 'es' },
    plugins: [
      typescript(),
    ]
  },
]

Yes, it's being worked.

And get many .d.ts files if the source is not one file.

There was any way to generate only one declaration file?

Was this page helpful?
0 / 5 - 0 ratings