Plugins ignored after 2nd item in list
I'm using the latest version of esbuild
Current Behavior
When running the esbuild.build script, I'm running into a weird issue where the method will ignore plugins after the second one in the list. If I swap the plugins in position 2/3 the latter one works and previous one doesn't.
Expected Behavior
The plugins in the list should run in order from first to last without being ignored.
Steps to reprodce
- Go here: https://github.com/pluralsight/tva/pull/676/files#diff-43d4aa6292fbf97935d4a2f7aa03a8935956f66f1a52ff0b4421e5ad5b73c9cf
- Clone branch and run
yarn create:bundles - Should see
BABEL WORKING...logged - ERROR - will not see
REPLACE WORKING...logged - but it should
This is because onLoad is being called only once per file. Your babel plugin and replace plugin both want to load a file, but only one of them could take control. See #1902 and https://gist.github.com/hyrious/ac6fd074c2f6d24a306c3a0970617cbc
I'd recommend you to write an all-in-one plugin that do all works in one onLoad currently.
@hyrious but that seems like a flaw in the esbuild system though since it is how all other bundlers work? Making an all in one will solve the problem, but it's a band-aid because we should be able to stack multiple esbuild plugins in a list vs one giant plugin (which contradicts clean coding practices).
In theory, the patch you are recommending is this:
plugins: [thirdParty, allIinOnePrivate, thirdParty]
Which will still fail.
I feel like esbuild should definitely be able to handle this case and allow the standard plugin syntax:
plugins: [thirdParty, private, thirdParty, thirdParty, etc.]
Ah, OK, I see this small line here in the plugin docs that only one plugin in the list should return the contents which tells esbuild to stop and move on to the next step, which aligns with what you were saying.
"For a given module, all onLoad callbacks from all plugins will be run in the order they were registered until one takes responsibility for loading the module. If no callback returns contents for the module, esbuild will run its default module loading logic."
Guessing all esbuild plugins should essentially not return contents to ensure the entire list gets looped through? 🤷♀️
It would be helpful to be able to invoke more than one onLoad callback or some different callback though for plugins that transform the code but otherwise want other plugins to work. This is quite an annoying limitation of esbuild currently.