Skip to content

Commit

Permalink
Merge pull request #1255 from ytbryan/stimulus-default-pack
Browse files Browse the repository at this point in the history
Support Stimulus Default Pack
  • Loading branch information
javan authored Feb 8, 2018
2 parents 8c6476e + 26559d8 commit 89e4d60
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
- [Angular with TypeScript](#angular-with-typescript)
- [Vue](#vue)
- [Elm](#elm)
- [Stimulus](#stimulus)
- [Coffeescript](#coffeescript)
- [Erb](#erb)
- [Paths](#paths)
Expand Down Expand Up @@ -325,6 +326,20 @@ The Elm library and core packages will be added via Yarn and Elm itself.
An example `Main.elm` app will also be added to your project in `app/javascript`
so that you can experiment with Elm right away.

### Stimulus

To use Webpacker with [Stimulus](http://stimulusjs.org), create a
new Rails 5.1+ app using `--webpack=stimulus` option:

```
# Rails 5.1+
rails new myapp --webpack=stimulus
```

(or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).

Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus

### Coffeescript

To add [Coffeescript](http://coffeescript.org/) support,
Expand Down
6 changes: 6 additions & 0 deletions lib/install/examples/stimulus/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("controllers", true, /.js$/)
application.load(definitionsFromContext(context))
18 changes: 18 additions & 0 deletions lib/install/examples/stimulus/controllers/hello_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Visit The Stimulus Handbook for more details
// https://stimulusjs.org/handbook/introduction
//
// This example controller works with specially annotated HTML like:
//
// <div data-controller="hello">
// <h1 data-target="hello.output"></h1>
// </div>

import { Controller } from "stimulus"

export default class extends Controller {
static targets = [ "output" ]

connect() {
this.outputTarget.textContent = 'Hello, Stimulus!'
}
}
12 changes: 12 additions & 0 deletions lib/install/stimulus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/application.js"
append_to_file "#{Webpacker.config.source_entry_path}/application.js" do
"\n" + open("#{__dir__}/examples/stimulus/application.js").read
end

say "Creating controllers directory"
directory "#{__dir__}/examples/stimulus/controllers", "#{Webpacker.config.source_path}/controllers"

say "Installing all Stimulus dependencies"
run "yarn add stimulus"

say "Webpacker now supports Stimulus.js 🎉", :green
3 changes: 2 additions & 1 deletion lib/tasks/installers.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ installers = {
"Vue": :vue,
"Erb": :erb,
"Coffee": :coffee,
"Typescript": :typescript
"Typescript": :typescript,
"Stimulus": :stimulus
}.freeze

dependencies = {
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/webpacker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tasks = {
"webpacker:install:vue" => "Installs and setup example Vue component",
"webpacker:install:angular" => "Installs and setup example Angular component",
"webpacker:install:elm" => "Installs and setup example Elm component",
"webpacker:install:stimulus" => "Installs and setup example Stimulus component",
"webpacker:install:erb" => "Installs Erb loader with an example",
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
"webpacker:install:typescript" => "Installs Typescript loader with an example"
Expand Down

0 comments on commit 89e4d60

Please sign in to comment.