Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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