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).
-
Run
npm install stimulus
-
Run
npm install babel-plugin-transform-class-properties --save-dev
-
Create
.babelrc
file in your project root, and paste in the following content:
{
"plugins": [
"babel-plugin-transform-class-properties"
]
}
-
Add a
controllers
directory underresources/js
(orresources/assets/js
if you're using Laravel 5.6 or lower). -
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));
- Run
npm run dev
, you're good to go!