新增
This commit is contained in:
+129
-129
@@ -1,129 +1,129 @@
|
||||
import * as fs from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { fileURLToPath, URL } from 'url'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
|
||||
// import legacyPlugin from '@vitejs/plugin-legacy'
|
||||
// https://vitejs.dev/config/
|
||||
|
||||
function getElementPlusStylePaths() {
|
||||
const componentsDir = path.resolve(
|
||||
__dirname,
|
||||
'node_modules',
|
||||
'element-plus',
|
||||
'es',
|
||||
'components'
|
||||
)
|
||||
const componentDirs = fs.readdirSync(componentsDir)
|
||||
|
||||
const stylePaths: string[] = []
|
||||
|
||||
// 遍历每个组件文件夹,检查是否有 `style/css` 文件
|
||||
componentDirs.forEach((dir) => {
|
||||
const stylePath = path.join(componentsDir, dir, 'style', 'index.mjs')
|
||||
if (fs.existsSync(stylePath)) {
|
||||
stylePaths.push(`element-plus/es/components/${dir}/style/css`)
|
||||
}
|
||||
})
|
||||
|
||||
return stylePaths
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const rawBase = (env.VITE_APP_BASE_URL || '').trim().replace(/\/+$/, '')
|
||||
const uploadsProxyTarget =
|
||||
rawBase.startsWith('http://') || rawBase.startsWith('https://')
|
||||
? rawBase
|
||||
: 'http://127.0.0.1:8080'
|
||||
|
||||
return {
|
||||
base: '/admin/',
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
hmr: true,
|
||||
open: true,
|
||||
proxy: {
|
||||
// 开发环境:相对路径 /uploads/* 由 PHP 提供,需转发到后端否则 Vite 端口下 404(录制回放黑屏)
|
||||
'/uploads': {
|
||||
target: uploadsProxyTarget,
|
||||
changeOrigin: true
|
||||
},
|
||||
'/api-proxy': {
|
||||
target: 'https://admin.zhenyangtang.com.cn',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api-proxy/, '')
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
AutoImport({
|
||||
imports: ['vue', 'vue-router'],
|
||||
resolvers: [ElementPlusResolver()],
|
||||
eslintrc: {
|
||||
enabled: true
|
||||
}
|
||||
}),
|
||||
Components({
|
||||
directoryAsNamespace: true,
|
||||
resolvers: [ElementPlusResolver()]
|
||||
}),
|
||||
createStyleImportPlugin({
|
||||
resolves: [ElementPlusResolve()]
|
||||
}),
|
||||
createSvgIconsPlugin({
|
||||
// 配置路劲在你的src里的svg存放文件
|
||||
iconDirs: [fileURLToPath(new URL('./src/assets/icons', import.meta.url))],
|
||||
symbolId: 'local-icon-[dir]-[name]'
|
||||
}),
|
||||
vueSetupExtend()
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
api: 'modern-compiler'
|
||||
}
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
// 确保不重复包含这些依赖
|
||||
include: ['@wangeditor/editor-for-vue', 'vue-echarts', ...getElementPlusStylePaths()]
|
||||
},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes('node_modules')) {
|
||||
const parts = id.toString().split('node_modules/')[1].split('/')
|
||||
// 保持 scoped 包按 @scope/name 拆分,避免所有 @tencentcloud/* 合成一个大 chunk
|
||||
if (parts[0]?.startsWith('@') && parts.length >= 2) {
|
||||
return `${parts[0]}/${parts[1]}`
|
||||
}
|
||||
return parts[0].toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
__VUE_PROD_DEVTOOLS__: false,
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_HYDRATION__: true,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
||||
}
|
||||
}
|
||||
})
|
||||
import * as fs from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { fileURLToPath, URL } from 'url'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
|
||||
// import legacyPlugin from '@vitejs/plugin-legacy'
|
||||
// https://vitejs.dev/config/
|
||||
|
||||
function getElementPlusStylePaths() {
|
||||
const componentsDir = path.resolve(
|
||||
__dirname,
|
||||
'node_modules',
|
||||
'element-plus',
|
||||
'es',
|
||||
'components'
|
||||
)
|
||||
const componentDirs = fs.readdirSync(componentsDir)
|
||||
|
||||
const stylePaths: string[] = []
|
||||
|
||||
// 遍历每个组件文件夹,检查是否有 `style/css` 文件
|
||||
componentDirs.forEach((dir) => {
|
||||
const stylePath = path.join(componentsDir, dir, 'style', 'index.mjs')
|
||||
if (fs.existsSync(stylePath)) {
|
||||
stylePaths.push(`element-plus/es/components/${dir}/style/css`)
|
||||
}
|
||||
})
|
||||
|
||||
return stylePaths
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const rawBase = (env.VITE_APP_BASE_URL || '').trim().replace(/\/+$/, '')
|
||||
const uploadsProxyTarget =
|
||||
rawBase.startsWith('http://') || rawBase.startsWith('https://')
|
||||
? rawBase
|
||||
: 'http://127.0.0.1:8080'
|
||||
|
||||
return {
|
||||
base: '/admin/',
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
hmr: true,
|
||||
open: true,
|
||||
proxy: {
|
||||
// 开发环境:相对路径 /uploads/* 由 PHP 提供,需转发到后端否则 Vite 端口下 404(录制回放黑屏)
|
||||
'/uploads': {
|
||||
target: uploadsProxyTarget,
|
||||
changeOrigin: true
|
||||
},
|
||||
'/api-proxy': {
|
||||
target: 'https://admin.zhenyangtang.com.cn',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api-proxy/, '')
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
AutoImport({
|
||||
imports: ['vue', 'vue-router'],
|
||||
resolvers: [ElementPlusResolver()],
|
||||
eslintrc: {
|
||||
enabled: true
|
||||
}
|
||||
}),
|
||||
Components({
|
||||
directoryAsNamespace: true,
|
||||
resolvers: [ElementPlusResolver()]
|
||||
}),
|
||||
createStyleImportPlugin({
|
||||
resolves: [ElementPlusResolve()]
|
||||
}),
|
||||
createSvgIconsPlugin({
|
||||
// 配置路劲在你的src里的svg存放文件
|
||||
iconDirs: [fileURLToPath(new URL('./src/assets/icons', import.meta.url))],
|
||||
symbolId: 'local-icon-[dir]-[name]'
|
||||
}),
|
||||
vueSetupExtend()
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
api: 'modern-compiler'
|
||||
}
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
// 确保不重复包含这些依赖
|
||||
include: ['@wangeditor/editor-for-vue', 'vue-echarts', ...getElementPlusStylePaths()]
|
||||
},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes('node_modules')) {
|
||||
const parts = id.toString().split('node_modules/')[1].split('/')
|
||||
// 保持 scoped 包按 @scope/name 拆分,避免所有 @tencentcloud/* 合成一个大 chunk
|
||||
if (parts[0]?.startsWith('@') && parts.length >= 2) {
|
||||
return `${parts[0]}/${parts[1]}`
|
||||
}
|
||||
return parts[0].toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
__VUE_PROD_DEVTOOLS__: false,
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_HYDRATION__: true,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user