opentiny / tiny-vue

TinyVue is an enterprise-class UI component library of OpenTiny community, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
https://opentiny.design/tiny-vue
MIT License
1.53k stars 251 forks source link

🐛 [Bug]: Failed to use tiny-vue as a plug-in #204

Closed ygj6 closed 1 year ago

ygj6 commented 1 year ago

Version

3.6.8

Vue Version

3.6.8

Link to minimal reproduction

正常创建vue工程,以插件方式使用 tiny-vue,如下:

import { createApp } from 'vue'
import Opentiny from '@opentiny/vue'
import './style.css'
import App from './App.vue'

createApp(App).use(Opentiny).mount('#app')

Step to reproduce

在vite环境下,执行npm dev

What is expected

启动工程正常

What is actually happening

启动工程报错

Any additional comments (optional)

全局引入 '@opentiny/vue' 时,无法确定 process.env的值 export const version = process.env.COMPONENT_VERSION

kagol commented 1 year ago

vite.config.ts 中添加以下代码:

  define: {
    'process.env': { ...process.env }
  }

例如:

// vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  define: {
    'process.env': { ...process.env }
  }
})

参考:https://opentiny.design/tiny-vue/zh-CN/os-theme/docs/installation