Resources

Summary

# Terminal
# Within the JS Library
git init stimulus-hello-world
cd stimulus-hello-world
yarn init
npm -g install microbundle
yarn build
yarn publish

# Within the Rails Application
yarn add stimulus
yarn add stimulus-hello-world
yarn upgrade-interactive --latest

# JS Library/package.json
{
  "name": "stimulus-hello-world",
  "version": "1.0.3",
  "description": "Stimulus Controller to alert Hello World",
  "main": "dist/stimulus-hello-world.js",
  "source": "src/index.js",
  "author": "Dave Kimura <email addresS",
  "license": "MIT",
  "private": false,
  "dependencies": {
    "stimulus": "^1.1.1"
  },
  "devDependencies": {
    "microbundle": "^0.11.0"
  },
  "scripts": {
    "build": "microbundle build",
    "dev": "microbundle watch"
  }
}

# JS Library/src/index.js
import { Controller } from 'stimulus'

export default class extends Controller {
  initialize() {
    alert('hello world v2')
  }
}

# Rails App /app/javascript/packs/application.js
import { Application } from 'stimulus'
const application = Application.start()

import HelloWorld from 'stimulus-hello-world'
application.register('hello-world', HelloWorld)

# Rails App /views/welcome/index.html.erb
<div data-controller='hello-world'></div>