rushstack
rushstack copied to clipboard
[heft-esbuild-plugin] Adds initial implementation of heft-esbuild-plugin
Summary
Added an initial implementation of an esbuild plugin for heft.
Details
This plugin currently uses the compile
run
hook to execute an esbuild build command. I used the compile hook because esbuild can be used to strip and compile TS code to JS. In this use-case its best to have this happen at the compile hook since its before bundling (though often in this scenario you also use the bundle
option too).
Config files look something like this:
{
"$schema": "../../../node_modules/@diwi/heft-esbuild-plugin/schemas/esbuild.schema.json",
"builds": [
{
"entryPoints": [
"src/main/index.ts",
"src/worker/worker.ts",
"src/lib/index.ts",
"src/service-worker/sw.ts"
],
"outdir": "dist",
"outbase": "src",
"bundle": true,
"format": "esm",
"target": [
"es2020",
"chrome90"
]
}
]
}
The configuration supports multiple 'builds', which can each define their own esbuild settings and entrypoints. This is useful for targetting different targets or formats in library projects.
The bundle
option does open the question of whether or not this should cause the build to only happen on the bundle hook though, and am open to exploring the impact of that change.
How it was tested
Currently this has been manually tested through publishing on an internal npm repository and then having a rig project use the above config. I will likely follow up with another PR for some other plugins and can then link to a public repo for the rig project that I'm using right now.
Would be interested to hear what the proposed automated test strategy is for heft plugins as I'm not seeing many examples of how to do jest testing for these plugins right now?
Obviously more work to be done on this. I'd like to expose more of the esbuild configuration options, and I think we should explore running in both compile
and bundle
stages. Interested to hear the teams feedback on this, we're not currently using it in any production projects, but I have a working example project that is using a rigged config project and a couple of other plugins that I'll submit separately (browsersync, workbox) to produce an example app.
Note: PR #3337 has renamed our GitHub master
branch to main
. This should not affect your pull request, but we recommend to redo your git clone
to avoid confusion with the old branch name.
@benjamind @iclanton we would love to use esbuild in heft - anything we can do to speed this up?
@benjamind @iclanton we would love to use esbuild in heft - anything we can do to speed this up?
@FullStackSteve I'm unlikely to complete this plugin at this point, feel free to take over the PR though!