Skip to content
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

feat: respect file extensions defined in package.json #505

Closed
wants to merge 1 commit into from

Conversation

kricsleo
Copy link
Contributor

@kricsleo kricsleo commented Feb 9, 2025

resolves #373
resolves #508

Converting to a draft PR for now, because I want to address the common output extensions issue.

@kricsleo kricsleo marked this pull request as draft February 13, 2025 02:12
@kricsleo
Copy link
Contributor Author

kricsleo commented Feb 13, 2025

Currently, the output file extensions (.mjs, .cjs) are fixed. This PR proposes inferring the entryFileNames and chunkFileNames extensions based on the package.json's entries config.

Motivation:

This allows users to customize output extensions to match their specific needs, addressing scenarios where the default .mjs and .cjs are not desired.

Example:

Given:

"exports": {
  ".": {
    "require": "./dist/index.js",
    "import": "./dist/index.mjs"
  }
}

The output would be:

dist
├── index.js   (cjs)
└── index.mjs  (esm)

Instead of the current:

dist
├── index.cjs  (cjs)
└── index.mjs  (esm)

Similarly:

"exports": {
  ".": {
    "require": "./dist/index.cjs",
    "import": "./dist/index.js"
  }
}

should generate:

dist
├── index.cjs (cjs)
└── index.js (esm)

Benefits:

This can resolve #508 (only concerned with esm).

Additionally, #373 (iife) can also be resolved because users can easily specify:

"main": "./dist/index.js"

so that the iife outputs also meet requirements.

I'd love to get feedbacks on this 🙏🏻.

@kricsleo kricsleo changed the title fix: use .js extension when format is iife feat: respect file extensions defined in package.json Feb 13, 2025
@pi0
Copy link
Member

pi0 commented Feb 13, 2025

unbuild is strictly opinionated about having .cjs/.mjs in output as it helps toolings to explicitly know the type of files without need to lookup for package.json (which at least has filesystem IO cost).

iife support is also non goal since unbuild is made for ESM (+CJS compat)

Thanks for PR ❤️

@pi0 pi0 closed this Feb 13, 2025
@kricsleo
Copy link
Contributor Author

Oh, I also agree with this point; appropriate restrictions lead to a better ecosystem. 👏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants