Repository is archived
No commit activity in last 3 years
No release in over 3 years
StimulusJS generator on Rails with Webpacker
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Stimulus generator for rails

This is generator for Stimulus on Rails application with Webpacker.

Installation

Add to your Gemfile:

gem 'stimulus-generator-rails'

Add this code to your webpacker's entrypoint javascript file:

import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("../javascripts/controllers", true, /\.js$/)
application.load(definitionsFromContext(context))

Usage

$ rails g stimulus CONTROLLER_NAME [action action]

# e.g.
$ rails g stimulus books index edit

Attention

This generator will create javascript and stylesheet into webpacker's source_entry_path/../javascripts/controllers and source_entry_path/../stylesheets. So if you set source_entry_path app/webpacker/entrypoint, you will see file structure like this:

app/webpacker
├── entrypoint
│   └── application.js
├── images
├── javascripts
│   └── controllers
│       └── books
│           └── index_controller.js
└── stylesheets
    └── books.scss

References