[@nx/esbuild:esbuild] Give precedence to config from esbuildOptions
or esbuildConfig
over executor options.
#23427
Replies: 2 comments
-
This issue has been automatically marked as stale because it hasn't had any activity for 6 months. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Description
Using a custom configuration either from using
esbuildOptions
oresbuildConfig
does not work for allesbuild
options. For example,esbuild
allows foriife
format1, while the executor options does not. Since the executor format default to["esm"]
, even not providing it will overrideesbuildOptions
oresbuildConfig
.I would like the behavior of the executor to use
esbuildOptions
oresbuildConfig
in 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
esbuild
own options, they are not one-to-one matches. Some (edge?) cases (such as usingiife
format or using aesbuild
plugins that requireswrite: false
) may need to deviate from the allowed executor options.Moreover, it would allow to support options that
esbuild
would 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
esbuildOptions
oresbuildConfig
options take precedence over executor options.Code-wise, here my two cents how I would see it done. However I do not know very well
Nx
ins 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.userDefinedBuildOptions
at the end of the object so that it overrides any options created by the executor.esbuild
for cases like commonality between all bundler executor, etc. (entryNames
,external
,sourcemap
seems 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.BuildOptions
that 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.
format
argument frombuildEsbuildOptions()
and uses the one provided inNormalizedEsBuildExecutorOptions.format
(an array) orNormalizedEsBuildExecutorOptions.userDefinedBuildOptions.format
(a single item).outExtension
and other functions that use limited configuration from whatesbuild
allows will probably need some gymnastics to be made more generic (and still valid!).buildEsbuildOptions()
to return an array ofesbuild.BuildOptions
based 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: false
is provided as a custom option2. Either haveNx
write the files or have theoutfile
empty (and let whatever uses that field to not fail, since havingwrite: false
means the use was deliberate in its decision).Alternate Implementations
esbuild
options; and updated each timeesbuild
add new options.Footnotes
iife
format is in fact the defaultesbuild
format whenbundling: true
andplatform: "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. Theoutfile
field seems to be populated, but since no files are created byesbuild
whatever uses that field fail later on. Some plugins relies onwrite: false
to either write themselves or expect the user to write the file themselves after the build process. ↩ ↩2Beta Was this translation helpful? Give feedback.
All reactions