[@nx/esbuild:esbuild] Give precedence to config from esbuildOptions or esbuildConfig over executor options.
#23427
Replies: 3 comments
|
This issue has been automatically marked as stale because it hasn't had any activity for 6 months. |
|
Hi! thanks for the detailed explanation, it is very much appreciated. I converted the issue to a discussion so that some design can be hashed out and allow others to chime in such that we could potentially implement this in the most non-breaking method possible |
|
I would like actually to specify my own entryNames as I need to place files under different folders |
Uh oh!
There was an error while loading. Please reload this page.
Description
Using a custom configuration either from using
esbuildOptionsoresbuildConfigdoes not work for allesbuildoptions. For example,esbuildallows foriifeformat1, while the executor options does not. Since the executor format default to["esm"], even not providing it will overrideesbuildOptionsoresbuildConfig.I would like the behavior of the executor to use
esbuildOptionsoresbuildConfigin priority over the executor options (obviously, when it does not prevent the good execution of the executor itself2).Motivation
While the executor options exposes most
esbuildown options, they are not one-to-one matches. Some (edge?) cases (such as usingiifeformat or using aesbuildplugins that requireswrite: false) may need to deviate from the allowed executor options.Moreover, it would allow to support options that
esbuildwould create in the future without having to write code to expose them explicitly.Suggested Implementation
On the end-user side, I would expect no changes in configuration format. However, it would be a breaking changes that the
esbuildOptionsoresbuildConfigoptions take precedence over executor options.Code-wise, here my two cents how I would see it done. However I do not know very well
Nxins and outs, so there are probably some cascading changes to be made also. But this is the gist of my idea.buildEsbuildOptions()spread operator onoptions.userDefinedBuildOptionsat the end of the object so that it overrides any options created by the executor.esbuildfor cases like commonality between all bundler executor, etc. (entryNames,external,sourcemapseems to be like that due to how they implement some decision factor based on executor options), they could be move after the spread operator. However, in that case, I think the executor should expose a slimmed down type ofesbuild.BuildOptionsthat remove/changes the allowed options.nx/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts
Lines 25 to 49 in 7942ea3
Other few ideas that could be useful in the refactoring.
formatargument frombuildEsbuildOptions()and uses the one provided inNormalizedEsBuildExecutorOptions.format(an array) orNormalizedEsBuildExecutorOptions.userDefinedBuildOptions.format(a single item).outExtensionand other functions that use limited configuration from whatesbuildallows will probably need some gymnastics to be made more generic (and still valid!).buildEsbuildOptions()to return an array ofesbuild.BuildOptionsbased on the requested format. That also mean, having to change to loop on the built options instead of the provided format in the implementation of both watch and buildwrite: falseis provided as a custom option2. Either haveNxwrite the files or have theoutfileempty (and let whatever uses that field to not fail, since havingwrite: falsemeans the use was deliberate in its decision).Alternate Implementations
esbuildoptions; and updated each timeesbuildadd new options.Footnotes
iifeformat is in fact the defaultesbuildformat whenbundling: trueandplatform: "browser"; two options exposed by the executor options. ↩For example, I tried to use
write: false, which failed because the executor expect the files to be created when it yield. Theoutfilefield seems to be populated, but since no files are created byesbuildwhatever uses that field fail later on. Some plugins relies onwrite: falseto either write themselves or expect the user to write the file themselves after the build process. ↩ ↩2All reactions