You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import checker from 'vite-plugin-checker'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'
import i18nBuildPlugin from './plugins/localesPlugin'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
// 组件库 的 vite.config.ts
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import checker from 'vite-plugin-checker'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'
import i18nBuildPlugin from './plugins/localesPlugin'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx(),
checker({
typescript: true,
// vueTsc: true,
overlay: {
initialIsOpen: false
}
}),
dts({
pathsToAliases: true,
outDir: ['./dist/es', './dist/lib'],
tsconfigPath: 'tsconfig.app.json',
exclude: ['vite.config.ts', 'vite.package.config.ts', './src', './plugins']
})
// i18nBuildPlugin()
],
//全局引入
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true
}
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@packages': fileURLToPath(new URL('./packages/src', import.meta.url))
}
},
build: {
lib: {
entry: resolve(__dirname, 'packages/src/index.ts')
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: ['vue', 'pinia', 'vue-router', 'axios'],
output: [
{
//打包格式
format: 'es',
//打包后文件名
entryFileNames: '[name].js',
//让打包目录和我们目录对应
preserveModules: true,
exports: 'named',
//配置打包根目录
dir: './dist/es',
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: 'Vue'
}
},
{
//打包格式
format: 'umd',
name: 'xxx',
//打包后文件名
entryFileNames: '[name].umd.js',
//让打包目录和我们目录对应
// preserveModules: true,
exports: 'named',
//配置打包根目录
dir: './dist/lib',
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: 'Vue'
}
}
]
}
}
})
组件库中引用是这样写的:
项目中使用的时候报找不到图片:
Beta Was this translation helpful? Give feedback.
All reactions