Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Build script #2

Closed
wants to merge 1 commit into from
Closed

Build script #2

wants to merge 1 commit into from

Conversation

jasoncharnes
Copy link

The default setup works great, even for React and JSX! That said, I think having the default build script mentioned in #1 would be a huge boost.

I've attempted to add a build script during the install process. To be clear, here- I'm very new to esbuild, so if there is a better way to do any of the things here I'm glad to change it!

  • Adds a build script: app/assets/config/esbuild.js
  • Changes the package.json build command to use the new script
    • I'm using the node command here, but it might be better as an executable. If someone could help me know what permissions to use for the executable I'd be glad to make that happen.
  • Turns on "watch" mode if --watch is one of the arguments passed to the build script
    • I lost the output when a build happens using watch mode, so I used the onRebuild function mentioned in the esbuild docs
    • I'm not overly enthusiastic about the overhead of reading the arguments and defining this function, but I do think having some type of feedback when a build occurs is valuable

.build({
entryPoints: ["app/javascript/application.js"],
bundle: true,
outfile: "app/assets/esbuilds/application.js",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be outdir: "app'assets/esbuilds" instead? That would allow multiple entryPoints out of the box.

Example:

entryPoints: ["app/javascript/application.js", "app/javascript/admin.js"],
outdir: "app/assets/esbuilds"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also prevents typos and follow naming conventions.

@dhh
Copy link
Member

dhh commented Sep 5, 2021

const watch = process.argv.includes("--watch") && {
   onRebuild(error) {
     if (error) console.error("[watch] build failed", error);
     else console.log("[watch] build finished");
   },
 };

This was the reason I backed off including this by default. It already smells like mini Webpacker 😂. I know it isn't, but I'm not a big fan of having actual code in here by default. Code that can go out of style and date easily.

I'd probably rather just link to somewhere that explains how to do this, and then stick with the command line for now.

@czj
Copy link

czj commented Sep 6, 2021

As I understand, to use Stimulus with esbuild — which I think is a common use case for Rails users — you need to use an import plugin like https://github.com/zombiezen/esbuild-plugin-stimulus and plugins only run via a build script, not the (much simpler and faster) esbuild command.

Could this repository's README be a good place to store information regarding esbuild build scripts then ? Or https://github.com/hotwired/stimulus-rails ?

@dhh
Copy link
Member

dhh commented Sep 6, 2021

czj, you don't have to use that. You can also just manually import and register your controllers. I'm working on a generated answer for that so we don't have to rely on a esbuild plugin.

@czj
Copy link

czj commented Sep 6, 2021 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants