Skip to content

Commit 4a6aee2

Browse files
authored
feat: add base option to import.meta.glob (#2018)
* feat: add base option to import.meta.glob * Vite バージョン変更
1 parent e4ebb82 commit 4a6aee2

File tree

3 files changed

+72
-29
lines changed

3 files changed

+72
-29
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
注意点:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"textlint-filter-rule-allowlist": "^4.0.0",
2020
"textlint-filter-rule-comments": "^1.2.2",
2121
"textlint-rule-preset-vuejs-jp": "git+https://github.com/vuejs-jp/textlint-rule-preset-vuejs-jp.git",
22-
"vite": "^6.3.5",
22+
"vite": "7.0.0-beta.1",
2323
"vitepress": "1.6.3",
2424
"vitepress-plugin-group-icons": "^1.6.0",
2525
"vitepress-plugin-llms": "^1.3.4",

pnpm-lock.yaml

Lines changed: 45 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)