-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(esbuild): add user esbuild plugins support #2886
Conversation
/** | ||
* Array of esbuild plugins to use. | ||
*/ | ||
esbuildPlugins?: EsbuildPlugin[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: IMO this should be part of ESBuildOptions
and not its own property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed, however it may introduce breaking changes, as Vite config esbuild
option (ESBuildOptions
) are passed directly to esbuild transform function, not to build function. See:
...options |
We could think about:
- Split the actual
esbuild
config into:
esbuild: {
transform: { /* the current `esbuild` options */ },
build: { plugins: [/* the esbuild plugins */] },
},
but this is a breaking change
- Keep the actual model and add
plugins
to it, orbuild.plugins
to be clearer and allow for more flexibility in future developments:
esbuild: {
/* actual options */,
build: { plugins: [/* the esbuild plugins */] },
},
and do delete resolvedOptions.build
in transformWithEsbuild
function before passing the options.
I am not convinced about the second solution.
I think the first one is much more clear, and we could go a step further by:
- using the root of
ebuild
options (as today) forinclude
,exclude
andjsxInject
options (which are deleted fromoptions
before the latter object is passed toesbuild.transform
– so doing so we avoid this deletion and directly passoptions.transform
toesbuild.transform()
, whileoptions.build
are passed directly toesbuild.build()
with an appropriate merge):
esbuild: {
include: ...,
exclude: ...,
jsxInject: `import React from 'react'`,
transform: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
build: {
plugins: [/* the esbuild plugins */],
/* other future options */
},
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 I really like your proposal 👍
@patak-js (@antfu) What are your thoughts about this?
Also IMO a breaking change shouldn't hold us back for such an improvement because it may be more future-proof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, if @patak-js and @antfu validate, I'll do the coding.
What is the roadmap for such a feature to be included in next minor ?
I'm pretty much impatient to use it ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like since optimizeDeps is an entirely different build phase than the esbuild transform options, the settings should go into config.optimizeDeps
. Here's a demonstration of that, perhaps this helps: #2991
I'd really like to get this functionality soon, since we're blocked by this in our conversion.
Description
Quoting esbuild-plugin-alias:
In my case, I had to shim all internal Vuetify
VIcon
imports to replace it with a custom and improved componentZIcon
. With vue-cli-3 and Webpack, all was fine. With Vite, I use this config:Aliases are properly handled by rollup at compilation. However, they are not matched by esbuild (the Vuetify component is imported).
I thought about adding internally to Vite an import to
esbuild-plugin-alias
and plug to it the config aliases, but not sure about side effects and the versatility of this solution – I guess it is an edge case, and more profitable to all if esbuid’s plugin system is exposed.Hence, I propose to add an entry
esbuildPlugins
to Vite config as such:Additional context
Do you think it is the correct way to tackle the above mentioned issue ?
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).