Closed lucfranken closed 6 years ago
well to install stimulus in rails you can use the official installer
https://github.com/rails/webpacker#stimulus
for a new app
rails new myapp --webpack=stimulus
or
to add it to an existing app
rails webpacker:install:stimulus
While it is well documented in webpacker a link in the handbook would be nice
@adrienpoly Thanks for the link and command! That did it!
The steps I took:
I run:
rails webpacker:install:stimulus
I get error:
rails webpacker:install:stimulus
rails aborted!
Don't know how to build task 'webpacker:install:stimulus' (see --tasks)
What I needed to do:
Add this to Gemfile:
gem 'webpacker', '~> 3.5'
Then:
bundle install
Then I got error:
rails webpacker:install:stimulus
Webpacker requires Yarn >= 0.25.2 and you are using 0.22.0
Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/
MacBook:myapp lucfranken$ bundle install
Then I go to: https://yarnpkg.com/lang/en/docs/install/ with a complicated story but luckily I had brew installed. So I run:
brew install yarn
That one fails too:
Error: yarn 0.22.0 is already installed
To upgrade to 1.6.0, run `brew upgrade yarn`
Then I run:
brew upgrade yarn
Then I run again:
rails webpacker:install:stimulus
Fails:
webpack binstubs not found.
Have you run rails webpacker:install ?
Make sure the bin directory or binstubs are not included in .gitignore
Exiting!
So I run:
rails webpacker:install
Then I run again:
rails webpacker:install:stimulus
π π π π π π π π π π π π π π π π π π
I then manually added this into application.html.erb layout:
<%= javascript_pack_tag 'application' %>
See, it doesn't really feel as smooth as installing Rails things. Hopefully this may become more easy in the future. I think for sure that the manual of Stimulus needs to have a clear direction towards your command:
rails webpacker:install:stimulus
Which is essentially the correct installation command but is missing.
@lucfranken
All in the same page.
Yarn 0.25.2+
gem 'webpacker', '~> 3.5'
bundle
bundle exec rails webpacker:install
bundle exec rails webpacker:install:stimulus
Thanks for the feedback! Feel free to start a new thread on https://discourse.stimulusjs.org/ if there's more to discuss.
@javan Thanks! Is this process something which your team would like improvement on? Or is it ok in current state for you and your team? Asking because the issue is closed, it's not totally clear for me whether improvement is desired here.
Example of my experience trying this for the first time, written as a beginner to see if we can find improvements:
But I got dragged into: https://stimulusjs.org/handbook/installing and other manuals and encounter:
Some code I really have no clue of why it's needed:
It's using paths like /src which seem familiar with React, coming from a Rails project they don't make sense.
It feels like it does not optimally support the nagging sense:
I don't know whether I want NPM or Yarn, or how they mix. I don't want to understand how controllers are loaded. I want to add some javascript feature like the example at the homepage: https://stimulusjs.org
Wouldn't it be possible to give the installation experience a more Rails like experience?
After a quite long time I found the Discourse forum via one of the issues. There seem to be more people experiencing this at first:
https://discourse.stimulusjs.org/t/organize-controllers-in-rails-app-without-webpacker/224 https://discourse.stimulusjs.org/t/work-with-rails/43