rollup / rollup/rollup

feat: option to keep imports when generating cjs as const destructoring pattern

Open
#4,448 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

t³ ✨ enhancement t⁸ ⋅ triage
Dominant language
JavaScript
Stars
26.3k
Forks
1.8k
Avg merge
2d 11h
Merged PRs (30d)
20

Description

Feature Use Case

Repl example
this example shows that it translates the import patterns to for example node_fs.existsSync but i need it to be
entrypoint.js

import { existsSync } from 'node:fs';
existsSync();

output.cjs

'use strict';

const node_fs = require('node:fs');

node_fs.existsSync();

but desired output should be:

'use strict';

const { existsSync } = require('node:fs');

existsSync();

what would be the best way to integrate that without simply patching the existing logic.

Feature Proposal

add a option that enables the desired output.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Rollup Repl example and compare the generated output.cjs with the desired destructuring pattern for entrypoint.js. Trace the CommonJS output generation path and define an option whose completed behavior preserves named imports instead of rewriting references through a namespace object, with coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.