Skip to content

Commit

Permalink
docs: update outdated references to globEager
Browse files Browse the repository at this point in the history
It was removed from Vite, now supported as an optional argument.
  • Loading branch information
ElMassimo committed Jan 3, 2025
1 parent b0d1812 commit 505a453
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/guide/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ or when all components should be registered in all pages.

```js
// app/frontend/entrypoints/application.js
import.meta.globEager('../../components/**/*_component.js')
import.meta.glob('../../components/**/*_component.js', { eager: true })
```

Any files imported from each `.js` file will be bundled as well.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guide/migrating-to-vite-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In Vite 3, [`import.meta.glob`](https://vitejs.dev/guide/migration.html#import-m

```ts
// app/frontend/controllers/index.js
const controllers = import.meta.globEager('../**/*_controller.js')
const controllers = import.meta.glob('../**/*_controller.js', { eager: true })
```

That code now transforms to:
Expand All @@ -51,7 +51,7 @@ Depending on the the pattern you might not need to make any changes, but if you
need the full path, you can leverage the new support for aliases:

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

:::tip Prefer Aliases
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ Proceed to fix any errors that occur (i.e. differences between Webpack and Vite.
+ <img src="<%= vite_asset_path('images/logo.svg') %>">
```

- Replace `require.context` with [`import.meta.glob`][glob] or [`import.meta.globEager`][glob].
- Replace `require.context` with [`import.meta.glob`][glob].

```diff
- const context = require.context("./controllers", true, /\.js$/)
+ const controllers = import.meta.globEager('./**/*_controller.js')
+ const controllers = import.meta.glob('./**/*_controller.js', { eager: true })
```

If you want to automatically register the Stimulus Controllers, have a look at <kbd>[stimulus-vite-helpers]</kbd> as a replacement for <kbd>@hotwired/stimulus-webpack-helpers</kbd>
Expand Down
2 changes: 1 addition & 1 deletion examples/rails/app/frontend/entrypoints/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ setTimeout(() => import('~/outer_import'), 5000)
import '@administrator/timer'

// Import all channels.
import.meta.globEager('../channels/**/*_channel.js')
import.meta.glob('../channels/**/*_channel.js', { eager: true })

Turbo.start()
ActiveStorage.start()
Expand Down
2 changes: 1 addition & 1 deletion test/test_app/app/frontend/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ console.log('Vite ⚡️ Rails')
// ActiveStorage.start()
//
// // Import all channels.
// const channels = import.meta.globEager('./**/*_channel.js')
// const channels = import.meta.glob('./**/*_channel.js', { eager: true })

// Example: Import a stylesheet in app/frontend/index.css
// import '~/index.css'
2 changes: 1 addition & 1 deletion vite_rails/templates/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify
// ActiveStorage.start()
//
// // Import all channels.
// const channels = import.meta.globEager('./**/*_channel.js')
// const channels = import.meta.glob('./**/*_channel.js', { eager: true })

// Example: Import a stylesheet in app/frontend/index.css
// import '~/index.css'
2 changes: 1 addition & 1 deletion vite_rails_legacy/templates/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify
// ActiveStorage.start()
//
// // Import all channels.
// const channels = import.meta.globEager('./**/*_channel.js')
// const channels = import.meta.glob('./**/*_channel.js', { eager: true })

// Example: Import a stylesheet in app/frontend/index.css
// import '~/index.css'

0 comments on commit 505a453

Please sign in to comment.