question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document Support for Esbuild

See original GitHub issue

Rails 7 seems to be moving away from webpack(er), with multiple options to bundle JS with the new js-bundling gem (e.g. with ESbuild etc.).

As such, in order to future proof the project, it might make sense to add support/documentation for JS bundling solutions other than webpack.

Notably, require.context() is webpack specific. I have managed to work around this by providing a mapping manually with ESbuild:

var ReactRailsUJS = require('react_ujs');
ReactRailsUJS.useContext({
  Table: require('./components/Table'),
});

As such, simply removing require.context() meant that I was able to successfully use react-rails with ESbuild.

This took quite some time to work out - as such, it would be useful to document this (or a better solution) somewhere.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:21

github_iconTop GitHub Comments

7reactions
louishuyngcommented, Feb 24, 2022

this one working fine with me

import components from './react/**/**.tsx';

let componentsContext = {};
components.forEach(component => {
  const name = Object.keys(component)[0];
  componentsContext[name] = component[name];
});

ReactRailsUJS.getConstructor = name => {
  return componentsContext[name];
};
ReactRailsUJS.handleEvent('turbo:load', ReactRailsUJS.handleMount, false);
ReactRailsUJS.handleEvent('turbo:frame-load', ReactRailsUJS.handleMount, false);
ReactRailsUJS.handleEvent('turbo:before-render', ReactRailsUJS.handleUnmount, false);
6reactions
dyejecommented, Jan 18, 2022

I made a guide based on @cionescu’s repo. I will try to make a PR with updated generators and README.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API - esbuild
Sources content; Supported; Tree shaking; Tsconfig raw. #Build API. The build API call operates on one or more files in the file system....
Read more >
Getting started with esbuild - LogRocket Blog
... CSS, and image files in this comprehensive esbuild tutorial. ... supports for React, CSS, and images, but it doesn't support SASS.
Read more >
AWS SAM CLI esbuild support is now generally available
To learn more about this feature, please read details in the documentation. To get started, you can install the SAM CLI by following...
Read more >
esbuild - npm
esbuild. This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the JavaScript API documentation for details.
Read more >
Introduction to esbuild - Telerik
We're going to cover what exactly esbuild is and how it can help us to ... Initially, JavaScript applications were simply single files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found