Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated installation code samples to use Stimulus constant #26

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,26 @@ composer require hotwired-laravel/stimulus-laravel
2. Create `resources/js/controllers/index.js` and load your controllers like this:

```js
import { application } from 'libs/stimulus'
import { Stimulus } from 'libs/stimulus'

// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from '@hotwired/stimulus-loading'
eagerLoadControllersFrom('controllers', application)
eagerLoadControllersFrom('controllers', Stimulus)
```

3. Create a `resources/js/libs/stimulus.js` with the following content:

```js
import { Application } from '@hotwired/stimulus'

const application = Application.start()
const Stimulus = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
Stimulus.debug = false

export { application }
window.Stimulus = Stimulus

export { Stimulus }
```

4. Create a `resources/js/libs/index.js` file with the following content (or add it to an existing file if you have one):
Expand Down Expand Up @@ -149,10 +150,10 @@ Importmap::pin("@hotwired/stimulus-loading", to: "vendor/stimulus-laravel/stimul
// Run that command whenever you add a new controller or create them with
// `php artisan stimulus:make controllerName`

import { application } from '../libs/stimulus'
import { Stimulus } from '../libs/stimulus'

import HelloController from './hello_controller'
application.register('hello', HelloController)
Stimulus.register('hello', HelloController)
```

#### Register controllers automatically
Expand All @@ -162,12 +163,12 @@ Importmap::pin("@hotwired/stimulus-loading", to: "vendor/stimulus-laravel/stimul
```js
// resources/js/controllers/index.js

import { application } from '../libs/stimulus'
import { Stimulus } from '../libs/stimulus'
import { registerControllers } from 'stimulus-vite-helpers'

const controllers = import.meta.glob('./**/*_controller.js', { eager: true })

registerControllers(application, controllers)
registerControllers(Stimulus, controllers)
```

And install the NPM package:
Expand All @@ -181,13 +182,14 @@ Importmap::pin("@hotwired/stimulus-loading", to: "vendor/stimulus-laravel/stimul
```js
import { Application } from '@hotwired/stimulus'

const application = Application.start()
const Stimulus = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
Stimulus.debug = false

window.Stimulus = Stimulus

export { application }
export { Stimulus }
```

3. Create a `resources/js/libs/index.js` file (if it doesn't exist) and add the following line to it:
Expand Down