[英]How do I install StimulusJS to a Ruby on Rails application?
How do I install StimulusJS to a Ruby on Rails application?如何将 StimulusJS 安装到 Ruby on Rails 应用程序?
The docs mention webpack
and npm
, but nothing about Rails or Yarn (at time of this writing).文档提到了
webpack
和npm
,但没有提到 Rails 或 Yarn(在撰写本文时)。
(Kind of strange given that Stimulus comes from Basecamp, who literally created RoR...) (有点奇怪,因为 Stimulus 来自 Basecamp,他确实创造了 RoR ......)
The answer, at least for Rails 6, is stunningly easy:至少对于 Rails 6,答案非常简单:
bundle exec rails webpacker:install:stimulus
That's it .就是这样。 That command will:
该命令将:
yarn
to download and install StimulusJSyarn
下载安装StimulusJSapp/javascript/packs/application.js
to import javascript controllersapp/javascript/packs/application.js
添加一行以导入 javascript 控制器app/javascript/controllers/index.js
(to load/init all stimulus controllers)app/javascript/controllers/index.js
(加载/初始化所有刺激控制器)app/javascript/controllers/hello_controller.js
app/javascript/controllers/hello_controller.js
添加演示控制器From there, you can create a simple view to use the demo Hello controller, and with a little tweaking you can make it just like the demo on the StimulusJS.org home page.从那里,您可以创建一个简单的视图来使用演示 Hello 控制器,通过一些调整,您可以使它就像StimulusJS.org主页上的演示一样。
Webpacker instructions for Stimulus are here: https://github.com/rails/webpacker#stimulus Stimulus 的 Webpacker 说明在这里: https : //github.com/rails/webpacker#stimulus
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.