-
-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple output targets with typescript declarations enabled #247
Comments
Does it work if you set two different |
I can try the two dir options tomorrow. For turning off declarations for the second output, would I have to use a different configuration template to achieve that than what I have posted? Wasn't sure how to specify output-specific plugin options |
Oops, I wasn't thinking straight...you'd need to provide two configurations. That's not ideal but should work as a quick fix for now until we improve the plugin further. |
I'm also facing this same issue, and when using a single output object with a dir property, TS definition files are not being generated. What do you mean by using two configurations @NotWoods? |
@Tylerian something like: // rollup.config.js
export default [
{
output: [
{
dir: 'dist',
format: 'es'
}
],
plugins: [typescript({ declaration: true }))]
},
{
output: [
{
file: 'index.cjs',
format: 'cjs'
}
],
plugins: [typescript({ declaration: false })]
}
]; I'm working on updating the plugin so |
@NotWoods FYI this did not work for me personally. I am curious, what's the harm in generating the declaration types twice other than wasted CPU? Wouldn't the second build output just overwrite the firsts? |
For me this worked, even though it's a bit ugly:
|
I'm running up against something similar to this, if you would prefer me to submit a new issue I wll. We use rollup to generate a single The new rollup typescript plugin enforces the use if rollup's Enforcing the use of chunks to deal with typescript declarations sounds like the wrong way to go imo. |
Hey folks. This is a call for contribution and help in resolving this TypeScript plugin issue. We're working with limited resources and the folks who can help have limited time. If you can help by triaging and submitting a Pull Request, we'd be happy to review it. |
Based on @openscript's solution I was able to get my configuration working and then make sense of the problems I was having. Firstly you need to make sure that your
The default export for my const rollup = (_args) => {
const input = 'src/index.ts';
const external = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})];
return [
// cjs configuration
{
input,
output: getOutput('cjs'),
plugins: getPlugins('cjs'),
external,
},
// esm configuration
{
input,
output: getOutput('esm'),
plugins: getPlugins('esm'),
external,
},
];
};
export default rollup;
const getOutput = (format = 'esm') => {
if (format === 'esm') {
return { dir: path.dirname(pkg.module), format };
}
// pkg is package.json
return { file: pkg.main, format };
}; and const getPlugins = (format = 'esm') => {
const typeScriptOptions = format === 'esm' ? { declaration: true, declarationDir: path.dirname(pkg.module) } : {};
return [
// @rollup/plugin-node-resolve
resolve({
browser: true,
extensions,
}),
typescript(typeScriptOptions),
// I'm using @rollup/plugin-babel so that I can use @babel/preset-env and @babel/preset-react
babel({
// this is needed because we're using TypeScript
babelHelpers: 'bundled',
extensions,
}),
];
}; It took me a while to figure out what was going on here, but:
Essentially it seems that if you try to generate declarations then you need to use My approach means that using this Rollup configuration is the only way I compile my TypeScript code (i.e. I don't use
Hope that helps! (As a suggestion maybe an edited form of this comment could go in the |
Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it. ⓘ |
Issue still relevant!!! works withiout declaration: true and ourDir, while add props those in config then
with multiple outputs. change file to dir - works but named files doesn't generate. Reopen issue please. |
We welcome contribution |
I've stopped using the rollup typescript plugin in favour of using Bit more to setup initially but it gives me far greater control over the process. |
Can we reopen to track this? |
@benmccann not until someone is willing to take this on. It was closed as stale bc it got no traction. |
@shellscape ok. I'm currently investigating this, so can we reopen as a result? |
Yessir! |
@benmccann Thanks for submitting a PR for this! Can you please provide a usage example? |
@benmccann any news? |
Unfortunately this still appears to be broken, the only way I can get declarations to work for multiple outputs is to do separate top-level tasks. |
I found that the single-file build also has such a problem. "rollup": "^3.2.5",
|
Man... I've spent the last 3 days trying to use rollup to build a tiny well behaved hello world react component library. Tutorials, rollup.config.js, package.json, & tsconfig formats and integrations seem to be ever changing in an unstable way, they all seem to depend on each other but differ vastly. Is there a better way to use Rollup? After all these changes to my project from trying to use rollup, I'm questioning how this will mess up my developer run mode. Might have to revert all rollup stuff, is there a better tool or standard tutorial for a well behaved NPM package these days? Thanks, frustrated. |
yeah, while I'm sorry you're having trouble with third party resources and rollup, this isn't the place to vent. we have discussions, a discord, and there's always Twitter and reddit. we've all been there, but please choose an appropriate medium next time. |
@rollup/typescript
4.0.0
Feature Use Case
I am coming from
rollup-plugin-typescript2
which seemed to allow settingdeclaration: true
as well as supporting multipleoutput
targets in therollup.config.js
like:partial tsconfig.json:
This plugin seems to only allow setting a single output target with the
dir
attribute, otherwise we get the "dir must be set when specifying declaration" error.Feature Proposal
Allow setting multiple output targets and default the declarations to the same directory as the current working directory of the output targets. From
rollup-plugin-typescript2
:I'm not sure its well defined for multiple output files, but maybe the default can just be the
declarationDir
specified instead of requiring rollup'soutput
to specify adir
The text was updated successfully, but these errors were encountered: