2026-08-25 10:15:37 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import setupExtend from 'unplugin-vue-setup-extend-plus/vite'
|
|
|
|
|
import path from 'node:path'
|
|
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
|
|
|
|
|
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
|
|
|
|
|
const externalDependencies = [
|
|
|
|
|
...Object.keys(packageJson.dependencies || {}),
|
|
|
|
|
...Object.keys(packageJson.peerDependencies || {})
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const peerDependencies = [
|
|
|
|
|
'vue',
|
|
|
|
|
'vue-router',
|
|
|
|
|
'pinia',
|
|
|
|
|
'element-plus',
|
|
|
|
|
'@element-plus/icons-vue'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
|
|
|
|
AutoImport({
|
|
|
|
|
imports: [
|
|
|
|
|
'vue',
|
|
|
|
|
'vue-router',
|
|
|
|
|
'pinia',
|
|
|
|
|
{
|
|
|
|
|
'@/utils/dict': ['useDict'],
|
|
|
|
|
'@/utils/ruoyi': ['selectDictLabel']
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
dts: false
|
|
|
|
|
}),
|
|
|
|
|
setupExtend()
|
|
|
|
|
],
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': path.resolve(import.meta.dirname, './src')
|
|
|
|
|
},
|
|
|
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
|
|
|
|
},
|
|
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
additionalData: `@use "${path.resolve(import.meta.dirname, './src/style/variable.scss').replaceAll('\\', '/')}" as *;`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
target: 'es2022',
|
2026-09-10 11:01:55 +08:00
|
|
|
// Keep published ESM chunks readable and safe for consumer Rollup builds.
|
|
|
|
|
// Consumers may bundle these chunks again; minifying here can cause short
|
|
|
|
|
// binding names to collide during that second pass.
|
|
|
|
|
minify: false,
|
2026-08-25 10:15:37 +08:00
|
|
|
sourcemap: true,
|
|
|
|
|
cssCodeSplit: false,
|
|
|
|
|
lib: {
|
|
|
|
|
entry: path.resolve(import.meta.dirname, 'src/index.js'),
|
|
|
|
|
formats: ['es'],
|
|
|
|
|
fileName: () => 'index.js',
|
|
|
|
|
cssFileName: 'style'
|
|
|
|
|
},
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
external: (id) => externalDependencies.some((dependency) => id === dependency || id.startsWith(`${dependency}/`)),
|
|
|
|
|
output: {
|
2026-09-10 11:01:55 +08:00
|
|
|
// Publish one self-contained ESM entry. Consumer Vite/Rollup builds
|
|
|
|
|
// otherwise merge the pre-generated chunks and can collide on the
|
|
|
|
|
// minified bindings used by different Vue SFC chunks.
|
|
|
|
|
inlineDynamicImports: true,
|
2026-09-07 10:52:30 +08:00
|
|
|
globals: {
|
|
|
|
|
vue: 'Vue',
|
|
|
|
|
'vue-router': 'VueRouter'
|
|
|
|
|
},
|
2026-08-25 10:15:37 +08:00
|
|
|
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
|
|
|
assetFileNames: (assetInfo) => assetInfo.name === 'style.css'
|
|
|
|
|
? 'style.css'
|
|
|
|
|
: 'assets/[name]-[hash][extname]'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|