Skip to content

Commit 2d0eeac

Browse files
committed
feat: add base option to import.meta.glob
1 parent e4ebb82 commit 2d0eeac

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

guide/features.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,32 @@ const modules = import.meta.glob('./dir/*.js', {
580580
})
581581
```
582582

583+
#### ベースパス
584+
585+
`base` オプションを使用して、インポートのベースパスを指定することもできます:
586+
587+
```ts twoslash
588+
import 'vite/client'
589+
// ---cut---
590+
const modulesWithBase = import.meta.glob('./**/*.js', {
591+
base: './base',
592+
})
593+
```
594+
595+
```ts
596+
// vite によって生成されたコード:
597+
const modulesWithBase = {
598+
'./dir/foo.js': () => import('./base/dir/foo.js'),
599+
'./dir/bar.js': () => import('./base/dir/bar.js'),
600+
}
601+
```
602+
603+
`base` オプションは、インポートするファイルからの相対ディレクトリパス、またはプロジェクトルートからの絶対パスのみ指定できます。エイリアスや仮想モジュールはサポートされていません。
604+
605+
相対パスであるグロブのみが、解決されたベースからの相対パスとして解釈されます。
606+
607+
結果として得られるすべてのモジュールキーは、ベースが指定されている場合にそこからの相対パスになるように変更されます。
608+
583609
### Glob インポートの注意事項
584610

585611
注意点:

0 commit comments

Comments
 (0)