Skip to content

Instantly share code, notes, and snippets.

@imjohnbon
Last active January 16, 2020 21:17
Show Gist options
  • Save imjohnbon/7de9ac3a75c680c62a4bbfe32716ef17 to your computer and use it in GitHub Desktop.
Save imjohnbon/7de9ac3a75c680c62a4bbfe32716ef17 to your computer and use it in GitHub Desktop.

This gist was made for Laravel 5.7, although it should work for any version. It also assumes you have a Laravel site set up and configured on a basic level (you ran composer install, npm install, created an app key, etc).

  1. Run npm install stimulus

  2. Run npm install babel-plugin-transform-class-properties --save-dev

  3. Create .babelrc file in your project root, and paste in the following content:

{
  "plugins": [
    "babel-plugin-transform-class-properties"
  ]
}
  1. Add a controllers directory under resources/js (or resources/assets/js if you're using Laravel 5.6 or lower).

  2. Add the following code to the top of app.js(taken directly from the Stimulus docs):

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));
  1. Run npm run dev, you're good to go!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment