如何使Rails 7编译JSX文件以进行React?

发布于 2025-02-10 22:15:48 字数 385 浏览 2 评论 0 原文

假设我在javascript/application/components/star_rating.js.jsx中有一个React模型,我想在我的JS代码中的其他地方做类似的事情:

    let starRating = <StarRating name={name} value={initialValue} onStarClick={onClick} />;
    ReactDOM.render(starRating, someContainerElem)

我现在应该如何使用Rails 7进行操作?

我过去曾经使用过轨道和反应,但从未轨道7。显然是Rails 7退休的Webpack。

如果有帮助,我曾经使用React-Rails Gem。

Suppose I have a React model in javascript/application/components/star_rating.js.jsx and I want to do something like this somewhere else in my JS code:

    let starRating = <StarRating name={name} value={initialValue} onStarClick={onClick} />;
    ReactDOM.render(starRating, someContainerElem)

How am I supposed to do that now with Rails 7?

I've used both Rails and React in the past but never Rails 7. Apparently Rails 7 retired Webpack.

I used to use the react-rails gem if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

獨角戲 2025-02-17 22:15:48

嗨,“某个家伙”

esbuild 处理,请参阅

它是Fat Webpacker和Asset Pipeline之间的中间方式。它“馈送”标准资产管道:它构建,并且该构建是通过资产管道将其传输到浏览器的。

这样,您正在通过 YARN添加而不是标准 importmap---- importmap----铁轨宝石。然后,软件包由 package.json 管理,就像您从WebPacker中知道的那样。

必须安装开发和生产计算机 node YARN ,并确保在应用程序目录内运行 YARN BUILD

您由 ./ bin/dev 运行的开发服务器,该服务器由 jsbundling-rails GEM添加。这将运行纱线构建-Watch 与PUMA并行,该在开发时会刷新浏览器,这与热模块重新装载一样,就像您从WebPackpacker-dev-Server中所知道的那样,但是超快。就我而言,使用Ruby Mine,在编码时按CMD+S,您会立即在浏览器上看到更改。

遵循上面的教程,您应该很好。

Hi "Some Guy"

esbuild handles that, see

its a middle way between the fat webpacker and the asset pipeline for its own. It "feeds" the standard asset pipeline: It builds, and that build is transferred by asset pipeline to the browser.

With that, javascript modules you are adding by yarn add instead of the standard importmap-rails gem. Packages then are managed by package.json like you know it from Webpacker.

On development and production machine node and yarn has to be installed and make sure that yarn build is running inside the app directory.

The development server you run by ./bin/dev which is added by jsbundling-rails gem. This runs yarn build --watch in parallel to puma which refreshes the browser while developing, unlike hot module reloading like you know it from webpacker-dev-server, but super fast. In my case, with ruby mine, press cmd+S while coding and you see the changes immediately on the browser.

Follow the tutorials above and you should be good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文