如何vite导入.meta.glob yaml文件

问题描述 投票:0回答:1

vite,import.meta.glob 如何读取 yaml 文件

import.meta.glob("../../locales/*.yaml",{eager:true})

未捕获的语法错误:意外的标识符“All”(位于 en.yaml?import:11:23)

javascript vue.js yaml vite
1个回答
0
投票

步骤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

完成。

© www.soinside.com 2019 - 2024. All rights reserved.