Set up Hotwire (importmap, Turbo, Stimulus) and fix bin/ci
The app was generated with 'rails new --skip', which skipped the JavaScript install step, leaving bin/importmap missing and bin/ci's importmap audit failing. Run the importmap, turbo, and stimulus install generators to wire up Hotwire per PRD 10.1/10.2 and restore bin/ci.
This commit is contained in:
3
app/javascript/application.js
Normal file
3
app/javascript/application.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
|
||||||
|
import "@hotwired/turbo-rails"
|
||||||
|
import "controllers"
|
||||||
9
app/javascript/controllers/application.js
Normal file
9
app/javascript/controllers/application.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Application } from "@hotwired/stimulus"
|
||||||
|
|
||||||
|
const application = Application.start()
|
||||||
|
|
||||||
|
// Configure Stimulus development experience
|
||||||
|
application.debug = false
|
||||||
|
window.Stimulus = application
|
||||||
|
|
||||||
|
export { application }
|
||||||
7
app/javascript/controllers/hello_controller.js
Normal file
7
app/javascript/controllers/hello_controller.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Controller } from "@hotwired/stimulus"
|
||||||
|
|
||||||
|
export default class extends Controller {
|
||||||
|
connect() {
|
||||||
|
this.element.textContent = "Hello World!"
|
||||||
|
}
|
||||||
|
}
|
||||||
4
app/javascript/controllers/index.js
Normal file
4
app/javascript/controllers/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Import and register all your controllers from the importmap via controllers/**/*_controller
|
||||||
|
import { application } from "controllers/application"
|
||||||
|
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
||||||
|
eagerLoadControllersFrom("controllers", application)
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
||||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||||
|
<%= javascript_importmap_tags %>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="min-h-screen bg-gray-50 text-gray-900 antialiased">
|
<body class="min-h-screen bg-gray-50 text-gray-900 antialiased">
|
||||||
|
|||||||
4
bin/importmap
Executable file
4
bin/importmap
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require_relative "../config/application"
|
||||||
|
require "importmap/commands"
|
||||||
7
config/importmap.rb
Normal file
7
config/importmap.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Pin npm packages by running ./bin/importmap
|
||||||
|
|
||||||
|
pin "application"
|
||||||
|
pin "@hotwired/turbo-rails", to: "turbo.min.js"
|
||||||
|
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
||||||
|
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
||||||
|
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||||
0
vendor/javascript/.keep
vendored
Normal file
0
vendor/javascript/.keep
vendored
Normal file
Reference in New Issue
Block a user