Skip to content

Commit

Permalink
feat(bundling): support rollup.config.ts (#29983)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Error when using rollup.config.ts
```
NX   Failed to process project graph.

2 errors occurred while processing files for the @nx/rollup/plugin plugin.
  - packages/codygen/rollup.config.cts: Unknown file extension ".cts" for /workspaces/codygen/packages/codygen/rollup.config.cts
  - sample3/rollup.config.ts: Unknown file extension ".ts" for /workspaces/codygen/sample3/rollup.config.ts 
```


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Plugin should be able to load rollup.config.ts

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #29982
  • Loading branch information
ThePlenkov authored Feb 25, 2025
1 parent b063fcd commit 63cb68d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/rollup/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ async function buildRollupTarget(
loadConfigFile = require('rollup/loadConfigFile').loadConfigFile;
}

const isTsConfig = configFilePath.endsWith('ts');
const tsConfigPlugin = '@rollup/plugin-typescript';
const namedInputs = getNamedInputs(projectRoot, context);
const rollupConfig = (
(await loadConfigFile(
joinPathFragments(context.workspaceRoot, configFilePath),
{},
isTsConfig ? { configPlugin: tsConfigPlugin } : {},
true // Enable watch mode so that rollup properly reloads config files without reusing a cached version
)) as { options: RollupOptions[] }
).options;
Expand All @@ -186,9 +188,7 @@ async function buildRollupTarget(
const targets: Record<string, TargetConfiguration> = {};
targets[options.buildTargetName] = {
command: `rollup -c ${basename(configFilePath)}${
configFilePath.endsWith('ts')
? ' --configPlugin @rollup/plugin-typescript'
: ''
isTsConfig ? ` --configPlugin ${tsConfigPlugin}` : ''
}`,
options: { cwd: projectRoot },
cache: true,
Expand Down

0 comments on commit 63cb68d

Please sign in to comment.