Skip to content

Commit 242fa6a

Browse files
committed
better setup for debug env vars
1 parent f567014 commit 242fa6a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

app/javascript/controllers/application.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { Application } from "@hotwired/stimulus"
22

33
const application = Application.start()
44

5-
// Configure Stimulus development experience
6-
application.debug = false
5+
// set `STIMULUS_DEBUG = 1` in `.env.local` to enable debug mode. see /app/views/layouts/application.html.erb
6+
if (document.head.querySelector("meta[name=stimulus_debug]")) {
7+
application.debug = true
8+
}
9+
710
window.Stimulus = application
811

912
export { application }

app/views/layouts/application.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
1010
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
11+
12+
<% if Rails.env == 'development' %>
13+
<%# set these values in .env.local %>
14+
<%= tag :meta, name: :stimulus_debug, content: true if ENV.fetch("STIMULUS_DEBUG", false) %>
15+
<% console if ENV.fetch("WEB_CONSOLE", false) %>
16+
<% end %>
1117
</head>
1218

1319
<body>
@@ -16,6 +22,5 @@
1622
<%= render "layouts/flash" %>
1723
</div>
1824
<%= yield %>
19-
<% console if Rails.env == 'development' && ENV["WEB_CONSOLE"] %>
2025
</body>
2126
</html>

0 commit comments

Comments
 (0)