Download the PHP package tonysm/stimulus-laravel without Composer
On this page you can find all versions of the php package tonysm/stimulus-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tonysm/stimulus-laravel
More information about tonysm/stimulus-laravel
Files in tonysm/stimulus-laravel
Package stimulus-laravel
Short Description Use Stimulus in your Laravel app
License MIT
Homepage https://github.com/hotwired-laravel/stimulus-laravel
Informations about the package stimulus-laravel
Introduction
Stimulus is a JavaScript framework with modest ambitions. It doesn’t seek to take over your entire front-end in fact, it’s not concerned with rendering HTML at all. Instead, it’s designed to augment your HTML with just enough behavior to make it shine. Stimulus pairs beautifully with Turbo to provide a complete solution for fast, compelling applications with a minimal amount of effort. Together they form the core of Hotwire.
Stimulus for Laravel makes it easy to use this modest framework with both import-mapped and JavaScript-bundled apps. It relies on either Importmap Laravel to make Stimulus available via ESM or a Node-capable Laravel using Vite to include Stimulus in the bundle. Make sure to install one of these first!
Inspiration
This package was inspired by the stimulus-rails gem.
Installation Steps
Stimulus Laravel may be installed via composer:
Next, if you're on a fresh Laravel app (see the #manual-installation if you're not), you may run install command:
That's it. The install command will automatically detect if you're using Importmap Laravel or Vite to manage your JavaScript dependencies. If you're using Importmap Laravel, we're pinning the Stimulus dependency and publishing a local dependency to your public/vendor
folder and pinning it so you don't have to register Stimulus controllers. If you're using Vite, we'll add the Stimulus dependecy to your package.json
.
The install command generates a resources/js/libs/stimulus.js
file that installs Stimulus. It also creates your first Stimulus controller at resources/js/libs/controllers/hello_controller.js
. It will also create a resources/js/libs/index.js
that ensures the resources/js/controllers/index.js
module is imported.
When using Importmap Laravel, the resources/js/controllers/index.js
will use the published stimulus-loading
dependency to either eager load or lazy load your Stimulus controller registrations automatically, so you don't have to manually register them. When using Vite, that file will be auto-generated whenever you make a new Stimulus controller or whenever you run the php artisan stimulus:manifest
manually.
Making a New Controller
To make a new Stimulus controller, run:
This should create the file for you using a scaffolding to get the controller ready for you. When using Vite, it will also regenerate the resources/js/controllers/index.js
file to register your newly created Stimulus controller automatically.
There's also a hint comment on how you may use the controller in the DOM, something like this:
Regenerate the Manifest
The stimulus:make
command will regenerate the resources/js/controllers/index.js
file for you, registering all your controllers. If you want to manually trigger a regeneration, you may run:
Manual Installation
If you're installing the package on an pre-existing Laravel app, it may be useful to manually install it step by step.
If you're using Importmap Laravel, follow the Vite steps.
- Either way, you need to install the lib via composer first:
Importmap Steps
-
Create
resources/js/controllers/index.js
and load your controllers like this: -
Create a
resources/js/libs/stimulus.js
with the following content: -
Create a
resources/js/libs/index.js
file with the following content (or add it to an existing file if you have one): -
Add the following line to your
resources/js/app.js
file: -
Publish the vendor dependencies:
-
Pin the Stimulus dependency:
- Finally, pin the
stimulus-loading
dependency on yourroutes/importmap.php
file:
Vite Steps
-
Create a
resources/js/controllers/index.js
and chose if you want to register your controllers manually or not:Register controllers manually
Register controllers automatically
If you prefer to automatially register your controllers you can use the
stimulus-vite-helpers
NPM package.And install the NPM package:
-
Create
resources/js/libs/stimulus.js
with the following content: -
Create a
resources/js/libs/index.js
file (if it doesn't exist) and add the following line to it: -
Add the following line to your
resources/js/app.js
file: - Finally, add the Stimulus package to NPM:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Drop me an email at [email protected] if you want to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
Credits
- Tony Messias
- All Contributors
All versions of stimulus-laravel with dependencies
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^10.0|^11.0