Skip to content

Instantly share code, notes, and snippets.

@existentialmutt
Last active August 3, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save existentialmutt/a9a6b3d07f11e44a2b14ee60c6321fb9 to your computer and use it in GitHub Desktop.
Save existentialmutt/a9a6b3d07f11e44a2b14ee60c6321fb9 to your computer and use it in GitHub Desktop.
Include JS from ruby gem with esbuild
import "my-gem"
require("esbuild").build({
//...
nodePaths: [process.env.NODE_PATH]
}).catch(() => process.exit(1));
//...
"scripts": {
"build": "NODE_PATH=$(bundle show --paths my-gem)/app/javascript node esbuild.config.js"
}
@existentialmutt
Copy link
Author

existentialmutt commented Aug 3, 2022

Configuration for including javascript direct from a gem with esbuild as commonly found in Rail

To avoid ambiguity put the gem's js under a name-specific folder in app/javascript

e.g.

app/javascript/my-gem/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment