rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[heft-esbuild-plugin] Adds initial implementation of heft-esbuild-plugin

Open benjamind opened this issue 3 years ago • 5 comments

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?

benjamind avatar Nov 03 '21 21:11 benjamind

CLA assistant check
All CLA requirements met.

ghost avatar Nov 03 '21 21:11 ghost

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.

benjamind avatar Nov 03 '21 21:11 benjamind

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.

iclanton avatar Apr 09 '22 02:04 iclanton

@benjamind @iclanton we would love to use esbuild in heft - anything we can do to speed this up?

FullStackSteve avatar Dec 20 '23 12:12 FullStackSteve

@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!

benjamind avatar Dec 20 '23 16:12 benjamind