vite,import.meta.glob 如何读取 yaml 文件
import.meta.glob("../../locales/*.yaml",{eager:true})
未捕获的语法错误:意外的标识符“All”(位于 en.yaml?import:11:23)
步骤1
安装@intlify/unplugin-vue-i18n - npm。
第2步
// vite.config.ts
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
import path from 'path'
export default defineConfig({
plugins: [
VueI18nPlugin({
include: [path.resolve(__dirname, './locales/**')],
}),
],
})
确保项目目录正确:
.
├── README.md
├── locales
│ └── zh-CN.yaml
├── node_modules
├── ...
├── src
│ ├──...
│ ├── plugins
│ │ └── i18n.ts
│ ├── main.ts
│ └── views
└── vite.config.ts
完成。