【发布时间】:2022-07-05 04:52:58
【问题描述】:
我想将我的 vue3+vite 包发布到 npm,但发布后,我在一个测试项目中遇到了“Uncaught TypeError: _ctx.$t is not a function”,我的包不工作,有什么建议...?
PS:我使用的是 vue options api
vite.configs.js:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueI18n from '@intlify/vite-plugin-vue-i18n'
// https://vitejs.dev/config/
const path = require("path")
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/install.ts'),
name: 'vcp',
fileName: (format) => `vcp.${format}.ts`
},
rollupOptions: {
external: ['vue'],
output: {
exports: 'named',
globals: {
vue: 'Vue',
vcp: 'Vcp'
}
}
},
},
plugins: [
vue(),
vueI18n({
include: path.resolve(__dirname, 'src/assets/translations.json'),
compositionOnly: false,
})
],
server: {
port: 8080
},
resolve: {
dedupe: ['vue'],
alias: {
"~": path.resolve(__dirname, "./src"),
"@": path.resolve(__dirname, "./src"),
},
},
})
【问题讨论】:
-
看看这个link,因为你的项目中是
$t。 -
我的问题是 vuei18n bundling tools for vite 而不是 vuei18n 本身,而 globalInjection 标志适用于 vuei18n