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

[Feature Request] Add --bundle-relative flag #1564

Closed
loynoir opened this issue Aug 30, 2021 · 3 comments
Closed

[Feature Request] Add --bundle-relative flag #1564

loynoir opened this issue Aug 30, 2021 · 3 comments

Comments

@loynoir
Copy link

loynoir commented Aug 30, 2021

Feature Request

Add --bundle-relative flag, only bundle all relative-alike files.

Scenario

Relative import may conflict, when using output extension .mjs.

#1563

Maybe

  • add extension name to relative importId,
  • or eliminate relative import doing a minimal bundling.

Description

import foo from '{{importId}}'
importId bundle Description
./foo true relative import
/{{packageRoot}}/foo true absolute import
/{{outside}}/foo false absolute import
#foo true subpath import
foo false namespace import and all else
#foo

https://nodejs.org/api/packages.html#packages_subpath_patterns

@hyrious
Copy link

hyrious commented Aug 30, 2021

You can write a plugin using onResolve to externalize paths outside of cwd.

@loynoir
Copy link
Author

loynoir commented Aug 30, 2021

@hyrious
It can.

But esbuild is awesome for out-of-box experience for typescript. Maybe add an external preset or something?

Or any plan for issue #1563?

@evanw
Copy link
Owner

evanw commented Oct 16, 2021

TypeScript's upcoming version 4.5 now has a way to do this. If you have a TypeScript file that needs to import another TypeScript file that will have a .mjs extension when compiled, you should use the .mts file extension for the TypeScript file and you should use import "./deps.mjs" in your TypeScript code to import deps.mts. This will be the official way to do it going forward and doesn't need any special support from esbuild. You can read the announcement here: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#new-file-extensions.

Closing this issue since this is being addressed outside of esbuild by the TypeScript team, and is possible to implement within esbuild via a plugin without needing to modify esbuild itself.

@evanw evanw closed this as completed Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants