如何使Rails 7编译JSX文件以进行React?
假设我在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。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗨,“某个家伙”
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 bypackage.json
like you know it from Webpacker.On development and production machine
node
andyarn
has to be installed and make sure thatyarn build
is running inside the app directory.The development server you run by
./bin/dev
which is added byjsbundling-rails
gem. This runsyarn 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.