Installing and configuring Stimulus
Before you can use Stimulus, you will need to download and install the framework. If you don’t want to complicate things, you can import it from its CDN. Just add the following script in the HTML template:
<script type="module" src= https://unpkg.com/@hotwired/[email protected]/dist/stimulus.js >
If you opt for this solution, you can ignore the rest of this section.
However, if you want to download Stimulus, which is very good practice, please note that it is available in the npm
packages, so let’s install it with a command:
npm i @hotwired/stimulus
From here, you have three different configuration possibilities: using Webpack, using another build system, or using the native JavaScript module system. We are going to focus on the last option, using modules, to simplify your implementation and not add more complexity:
- Copy the Stimulus file to a folder inside
static
, for example, in thestatic/js...