File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff 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注意点:
You can’t perform that action at this time.
0 commit comments