-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to achieve something similar to babel's require.context macro? #322
Comments
This isn't possible with esbuild. If you need to use Babel plugins like this, then you will likely need to use Babel. The only alternative that works with esbuild at the moment is to explicitly list out all of the imports in code. This could either be done manually by actually writing the imports yourself, or by a script that runs before esbuild and automatically generates a file containing the imports for esbuild to consume. Babel macros could be potentially integrated into esbuild when the esbuild plugin API is released in the future, but it may negate a lot of the speed benefits of esbuild depending on how the plugin works. The esbuild plugin API is not ready yet but you can follow issue #111 for updates. |
Thanks for the quick reply. I would be trying this script generation hack today.
It would be really nice to see this supported natively.
Thanks,
Vijay
…________________________________
From: Evan Wallace <[email protected]>
Sent: Monday, August 10, 2020 9:05:25 AM
To: evanw/esbuild <[email protected]>
Cc: Vijay Britto <[email protected]>; Author <[email protected]>
Subject: Re: [evanw/esbuild] How to achieve something similar to babel's require.context macro? (#322)
This isn't possible with esbuild. If you need to use Babel plugins like this, then you will likely need to use Babel.
The only alternative that works with esbuild at the moment is to explicitly list out all of the imports in code. This could either be done manually by actually writing the imports yourself, or by a script that runs before esbuild and automatically generates a file containing the imports for esbuild to consume.
Babel macros could be potentially integrated into esbuild when the esbuild plugin API is released in the future, but it may negate a lot of the speed benefits of esbuild depending on how the plugin works. The esbuild plugin API is not ready yet but you can follow issue #111<#111> for updates.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#322 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA4NSZGQG3IRMF6H2IU3LUTR75TH3ANCNFSM4PZPT2OA>.
|
Closing. I'm not intending to add this feature to esbuild itself. It should be possible to do something like this yourself with the plugin API if you really need it. |
Maybe this is interesting for you @vijaybritto: https://github.com/thomaschaaf/esbuild-plugin-import-glob |
@thomaschaaf this is amazing! I wrote a custom plugin for our company codebase which does exactly the same! |
Our codebase uses this babel Macro in multiple places. This breaks when compiled with esbuild . Is there a way to replicate this dynamic loading of modules?
The use cases are usually for dynamic loading multiple icons/images in a folder.
The text was updated successfully, but these errors were encountered: