-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Specifying plugins via the CLI #884
Comments
Sorry, esbuild's plugin API is intentionally designed to be accessible via JavaScript instead of the CLI. IMO using JavaScript is much more intuitive and ergonomic than a CLI for complex configuration scenarios. I don't really have any plans to change this at the moment. I'm completely unfamiliar with what AWS CDK is, so my apologies if something I'm saying doesn't make sense. With that caveat in mind, some possible workarounds for you off the top of my head:
Do any of those work for you? I may in the far future explore a plugin API for binary plugins. If I do that, there's a possibility that they might be enabled for CLI usage. See #111 (comment) for more information. But right now I am not planning on taking esbuild's plugin API in this direction. |
A bit of a hack but, does creating an alias to npx solve the issue ? Maybe aliasing npx to "yarn" or "yarn dlx" would do ? |
@evanw in the PnP resolver plugin's case, it just needs to be imported. No other configuration for it is required. There is a workaround possible, by disabling PnP, but that's not a good solution for bigger monorepos that rely on it. This is also related: #237 (comment) A way to simply allow specifying a plugin, but for the CLI would be great. This is all that is needed: import {pnpPlugin} from '@yarnpkg/esbuild-plugin-pnp';
await build({
plugins: [pnpPlugin()],
// ...
}); I noticed that the possibility of an An module.exports = {
plugins: ['@yarnpkg/esbuild-plugin-pnp']
} or import {pnpPlugin} from '@yarnpkg/esbuild-plugin-pnp';
module.exports = {
plugins: [pnpPlugin]
} There are various tools already written that use the |
This kind of makes sense from a "complexity within esbuild" standpoint but unfortunately the API isn't equivalent to the CLI. I just used it successfully and the first thing I notice is that I no longer get a list of outputted files, stats, and watching status. I also have to deal with running the file myself, e.g. I have to use ts-node: node --loader ts-node/esm esbuild.ts |
@fregante You can get output stats with Talk back to the issue, I have made Other solutions like antfu/esno use require.extensions / loaders to not pollute the file system and provide better experience at One thing I'd like to have is loading plugins from the global scope like rollup. But I haven't got the trick to implement that. |
Another vote for specifying plugins via CLI. CDK has us limited to builtin loaders, for which there isn't one for |
We're in a similar situation - It would be much appreciated if we could add plugins by pointing to a |
It would be awesome to have that +1 to @VanTanev proposal. |
+1 for this. When using nix expressions, the derivation only exposes esbuild CLI, to use plugins with esbuild in this context, one need to build a js-backed derivation to inject plugins, it just does not worth the added complexity. |
+1 for this need this to simplify bundling using CDK aws-lambda-nodejs |
The same issue here with aws-cdk |
similar issue here |
I'm closing this issue because I'm not planning on doing this. For what it's worth esbuild has since added native support for Yarn PnP, so the concern in the original issue should be resolved by just updating esbuild. |
Disappointing, as even Rollup has pulled this off without headache. |
FWIW, vite might be a good replacement for esbuild in this case, given that it support more features without the need for plugins. |
guess what vite uses under the hood? 😉 |
Hey @evanw, thank you for the amazing work on esbuild! I wanted to ask, could you reconsider this issue? I know that is of no fault of yours, and you have no obligation to take on the burden of supporting extra features in esbuild. Still, it would be really helpful for us, and other teams that need to bundle through cdk. Having the option to either specify a config file, or a file with a plugin to be loaded from the cli would be a God sent. Thank you! |
This isn’t straightforward on esbuild’s side because the CLI is native code and doesn’t contain a JavaScript interpreter. This feels like something that sounds be fixed on AWS’s side instead. If they want to support JavaScript plugins, they should be using esbuild’s JavaScript API instead of the CLI. Please file an issue with them about it. |
FWIW, I worked around this issue with https://github.com/mrgrain/cdk-esbuild |
This is the relevant CDK issue FYI aws/aws-cdk#18470 |
Stumbled here too - sprae needs CDN version, but first limitation of esbuild - it doesn't have UMD output format. |
@dy please take a look at this merge |
32k loc... can you be more specific? For now I just made .esbuild.js |
Yes this is the relevant section of the README You can create your own |
aws-cdk
currently usesesbuild
to bundle code used for lambdas: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.htmlUnfortunately, because of internal implementation details in
aws-cdk
, the esbuild nodejs API cannot be used directly. Ref: aws/aws-cdk#13179 (comment)So they can only use the
CLI
to spawnesbuild
.The problem is that when used in conjunction with Yarn v2 and PnP, this plugin needs to be added: https://github.com/yarnpkg/berry/tree/master/packages/esbuild-plugin-pnp
Currently
esbuild
does not seem to allow specifying plugins via a CLI option, so Yarn PnP cannot work with the aws-cdk esbuild implementation. Ref: aws/aws-cdk#13257 (comment) (there's a workaround possible, but it makes things pretty complicated)Would it be possible to allow specifying the plugin via the CLI? Or via some configuration file perhaps? (some file like
.esbuildrc
could be an option)The text was updated successfully, but these errors were encountered: