Skip to content

Will tsdown support the inject option? #108

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

Open
Groupguanfang opened this issue Apr 18, 2025 · 3 comments
Open

Will tsdown support the inject option? #108

Groupguanfang opened this issue Apr 18, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@Groupguanfang
Copy link

Reference: esbuild-inject

This is really useful. It not only provides a shims as the official website of esbuild says, but also can actually be used to import some polyfills for entry.

@yyx990803
Copy link
Member

Rolldown supports inject natively: https://rolldown.rs/reference/config-options#inject

We just need to document how to pass raw Rolldown options.

@Groupguanfang
Copy link
Author

Groupguanfang commented Apr 18, 2025

Speaking of this, what if I want to just import a package directly, like import 'foo'? I don’t seem to have seen this method in rolldown’s JSDoc.🤔

/**
 * Inject import statements on demand.
 *
 * ## Supported patterns
 * ```js
 * {
 *   // import { Promise } from 'es6-promise'
 *   Promise: ['es6-promise', 'Promise'],
 *
 *   // import { Promise as P } from 'es6-promise'
 *   P: ['es6-promise', 'Promise'],
 *
 *   // import $ from 'jquery'
 *   $: 'jquery',
 *
 *   // import * as fs from 'node:fs'
 *   fs: ['node:fs', '*'],
 *
 *   // Inject shims for property access pattern
 *   'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
 * }
 * ```
 */
inject?: Record<string, string | [string, string]>;

@sxzz
Copy link
Member

sxzz commented Apr 18, 2025

Rolldown's inject is incompatible with and different from esbuild's, so I haven't moved the inject option to the top-level configuration.

@sxzz sxzz added the documentation Improvements or additions to documentation label Apr 18, 2025
@sxzz sxzz added enhancement New feature or request and removed documentation Improvements or additions to documentation labels May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants