From 505a4530df19e3e59d3e34e32c0516f8e75e72de Mon Sep 17 00:00:00 2001 From: Maximo Mussini Date: Fri, 3 Jan 2025 16:35:16 -0300 Subject: [PATCH] docs: update outdated references to globEager It was removed from Vite, now supported as an optional argument. --- docs/src/guide/advanced.md | 2 +- docs/src/guide/migrating-to-vite-3.md | 4 ++-- docs/src/guide/migration.md | 4 ++-- examples/rails/app/frontend/entrypoints/application.ts | 2 +- test/test_app/app/frontend/entrypoints/application.js | 2 +- vite_rails/templates/entrypoints/application.js | 2 +- vite_rails_legacy/templates/entrypoints/application.js | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/src/guide/advanced.md b/docs/src/guide/advanced.md index c43793f1..d684dbc8 100644 --- a/docs/src/guide/advanced.md +++ b/docs/src/guide/advanced.md @@ -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. diff --git a/docs/src/guide/migrating-to-vite-3.md b/docs/src/guide/migrating-to-vite-3.md index 9d3f22dc..cdd400c9 100644 --- a/docs/src/guide/migrating-to-vite-3.md +++ b/docs/src/guide/migrating-to-vite-3.md @@ -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: @@ -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 diff --git a/docs/src/guide/migration.md b/docs/src/guide/migration.md index 4ba788e3..6d91a81d 100644 --- a/docs/src/guide/migration.md +++ b/docs/src/guide/migration.md @@ -90,11 +90,11 @@ Proceed to fix any errors that occur (i.e. differences between Webpack and Vite. + ``` -- 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 [stimulus-vite-helpers] as a replacement for @hotwired/stimulus-webpack-helpers diff --git a/examples/rails/app/frontend/entrypoints/application.ts b/examples/rails/app/frontend/entrypoints/application.ts index fded5147..4fbbd176 100644 --- a/examples/rails/app/frontend/entrypoints/application.ts +++ b/examples/rails/app/frontend/entrypoints/application.ts @@ -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() diff --git a/test/test_app/app/frontend/entrypoints/application.js b/test/test_app/app/frontend/entrypoints/application.js index 1d7b37b0..12dd1f5e 100644 --- a/test/test_app/app/frontend/entrypoints/application.js +++ b/test/test_app/app/frontend/entrypoints/application.js @@ -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' diff --git a/vite_rails/templates/entrypoints/application.js b/vite_rails/templates/entrypoints/application.js index b679e2ab..ff27427f 100644 --- a/vite_rails/templates/entrypoints/application.js +++ b/vite_rails/templates/entrypoints/application.js @@ -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' diff --git a/vite_rails_legacy/templates/entrypoints/application.js b/vite_rails_legacy/templates/entrypoints/application.js index b679e2ab..ff27427f 100644 --- a/vite_rails_legacy/templates/entrypoints/application.js +++ b/vite_rails_legacy/templates/entrypoints/application.js @@ -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'