rails stimulus:manifest:update removes components from manifest
Hello,
Having an issue with the way we import stimulus components.
Every component installation is made using yarn install stimulus-component-xyz and manually editing index.js to add the new component.
My problem lies with the command found on hotwired/stimulus-rails
rails stimulus:manifest:update
I use it to add my own controllers and ensure old ones are removed from the index.js The problem is that it also removes the stimulus component i added manually.
What's expected
Stimulus components import method should not be deleted when using rails stimulus:manifest:update. I doubt it's doable though since we have no control over this.
At least documentation should warn us from using that command and provide an alternative since hotwired is the default way in rails 7 this will probably happen to more people.
What's happening
Running rails stimulus:manifest:update removes all manually added stimulus components
Repro
-
clone the repository
-
notice app/javascript/controllers/index.js contains:
import ScrollTo from 'stimulus-scroll-to
application.register('scroll-to', ScrollTo)
- Run
rails stimulus:manifest:update - Notice that app/javascript/controllers/index.js no longer holds references to scrollTo component
Should I just stop using rails stimulus:manifest:update and only create my controllers using rails generate stimulus controllerName ?
Thank you
@ophilbert I am having the same issue, would you mind share what's your final approach? 😊
I ended up stopping using rails stimulus:manifest:update
and manually editing the index file. Not the best solution but I don’t add new controllers every day so it’s fine this way.
Le mer. 27 juil. 2022 à 07:21, Hungmi @.***> a écrit :
@ophilbert https://github.com/ophilbert I am having the same issue, would you mind share what's your final approach? 😊
— Reply to this email directly, view it on GitHub https://github.com/stimulus-components/stimulus-components/issues/47#issuecomment-1196277853, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN3ITIEYEFDB7OTXTF3WI3VWDBOTANCNFSM5UHSYO4Q . You are receiving this because you were mentioned.Message ID: @.***>
-- Olivier Philbert
Yeah I think stimulus:manifest:update is more for local controllers 👍
A solution might be to register Stimulus Components via an alternate components.js file.
- Create the file app/javascript/components.js
// app/javascript/components.js
import { application } from "./controllers/application"
import Autosave from 'stimulus-rails-autosave'
application.register('autosave', Autosave)
- Import components.js by adding this line to app/javascript/application.js:
// app/javascript/application.js
...
import "./components"
...
This way, app/javascript/controllers/index.js can be used for local controllers only, and app/javascript/components.js for manually installed Stimulus Components.