From 34e9c28113ca5d4792d8e358ba088300b4e1a4ff Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Thu, 27 Feb 2025 16:56:40 +0900 Subject: [PATCH 1/2] docs: make `import.meta.glob` example code more accurate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #1871 https://github.com/vitejs/vite/commit/ce0ccc6c33544a14728fff4b84c746c9682f9878 の反映です。 --- guide/features.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/guide/features.md b/guide/features.md index 12995eb6..c614d9aa 100644 --- a/guide/features.md +++ b/guide/features.md @@ -423,8 +423,8 @@ const modules = import.meta.glob('./dir/*.js') ```js // vite によって生成されたコード const modules = { - './dir/foo.js': () => import('./dir/foo.js'), './dir/bar.js': () => import('./dir/bar.js'), + './dir/foo.js': () => import('./dir/foo.js'), } ``` @@ -450,11 +450,11 @@ const modules = import.meta.glob('./dir/*.js', { eager: true }) ```js // vite によって生成されたコード -import * as __glob__0_0 from './dir/foo.js' -import * as __glob__0_1 from './dir/bar.js' +import * as __vite_glob_0_0 from './dir/bar.js' +import * as __vite_glob_0_1 from './dir/foo.js' const modules = { - './dir/foo.js': __glob__0_0, - './dir/bar.js': __glob__0_1, + './dir/bar.js': __vite_glob_0_0, + './dir/foo.js': __vite_glob_0_1, } ``` @@ -498,8 +498,8 @@ const modules = import.meta.glob('./dir/*.js', { import: 'setup' }) ```ts // vite によって生成されたコード const modules = { - './dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup), './dir/bar.js': () => import('./dir/bar.js').then((m) => m.setup), + './dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup), } ``` @@ -516,11 +516,11 @@ const modules = import.meta.glob('./dir/*.js', { ```ts // vite によって生成されたコード: -import { setup as __glob__0_0 } from './dir/foo.js' -import { setup as __glob__0_1 } from './dir/bar.js' +import { setup as __vite_glob_0_0 } from './dir/bar.js' +import { setup as __vite_glob_0_1 } from './dir/foo.js' const modules = { - './dir/foo.js': __glob__0_0, - './dir/bar.js': __glob__0_1, + './dir/bar.js': __vite_glob_0_0, + './dir/foo.js': __vite_glob_0_1, } ``` @@ -537,11 +537,11 @@ const modules = import.meta.glob('./dir/*.js', { ```ts // vite によって生成されたコード: -import __glob__0_0 from './dir/foo.js' -import __glob__0_1 from './dir/bar.js' +import { default as __vite_glob_0_0 } from './dir/bar.js' +import { default as __vite_glob_0_1 } from './dir/foo.js' const modules = { - './dir/foo.js': __glob__0_0, - './dir/bar.js': __glob__0_1, + './dir/bar.js': __vite_glob_0_0, + './dir/foo.js': __vite_glob_0_1, } ``` @@ -565,12 +565,12 @@ const moduleUrls = import.meta.glob('./dir/*.svg', { ```ts // vite によって生成されるコード: const moduleStrings = { - './dir/foo.svg': () => import('./dir/foo.js?raw').then((m) => m['default']), './dir/bar.svg': () => import('./dir/bar.js?raw').then((m) => m['default']), + './dir/foo.svg': () => import('./dir/foo.js?raw').then((m) => m['default']), } const moduleUrls = { - './dir/foo.svg': () => import('./dir/foo.js?url').then((m) => m['default']), './dir/bar.svg': () => import('./dir/bar.js?url').then((m) => m['default']), + './dir/foo.svg': () => import('./dir/foo.js?url').then((m) => m['default']), } ``` From c1074023d2315e4a386dfbebc0296bcc4088df7c Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Thu, 27 Feb 2025 20:58:36 +0900 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Jun Shindo <46585162+jay-es@users.noreply.github.com> --- guide/features.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guide/features.md b/guide/features.md index c614d9aa..3bcc5148 100644 --- a/guide/features.md +++ b/guide/features.md @@ -565,12 +565,12 @@ const moduleUrls = import.meta.glob('./dir/*.svg', { ```ts // vite によって生成されるコード: const moduleStrings = { - './dir/bar.svg': () => import('./dir/bar.js?raw').then((m) => m['default']), - './dir/foo.svg': () => import('./dir/foo.js?raw').then((m) => m['default']), + './dir/bar.svg': () => import('./dir/bar.svg?raw').then((m) => m['default']), + './dir/foo.svg': () => import('./dir/foo.svg?raw').then((m) => m['default']), } const moduleUrls = { - './dir/bar.svg': () => import('./dir/bar.js?url').then((m) => m['default']), - './dir/foo.svg': () => import('./dir/foo.js?url').then((m) => m['default']), + './dir/bar.svg': () => import('./dir/bar.svg?url').then((m) => m['default']), + './dir/foo.svg': () => import('./dir/foo.svg?url').then((m) => m['default']), } ```