| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import legacyPlugin from '@vitejs/plugin-legacy'
- import AutoImport from 'unplugin-auto-import/vite'
- import Components from 'unplugin-vue-components/vite'
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
- import Banner from 'vite-plugin-banner'
- import * as path from 'path'
- import * as dotenv from 'dotenv'
- import * as fs from 'fs'
- import vuePlugin from '@vitejs/plugin-vue'
- import GvaPosition from './vitePlugin/gvaPosition'
- import GvaPositionServer from './vitePlugin/codeServer'
- import fullImportPlugin from './vitePlugin/fullImport/fullImport.js'
- import { svgBuilder } from './vitePlugin/svgIcon/svgIcon.js'
- // @see https://cn.vitejs.dev/config/
- export default ({ command, mode }) => {
- const NODE_ENV = mode || 'development'
- const envFiles = [`.env.${NODE_ENV}`]
- for (const file of envFiles) {
- const envConfig = dotenv.parse(fs.readFileSync(file))
- for (const k in envConfig) {
- process.env[k] = envConfig[k]
- }
- }
- const timestamp = Date.parse(new Date())
- const optimizeDeps = {}
- const alias = {
- '@': path.resolve(__dirname, './src'),
- vue$: 'vue/dist/vue.runtime.esm-bundler.js'
- }
- const esbuild = {}
- const rollupOptions = {
- output: {
- entryFileNames: 'assets/087AC4D233B64EB0[name].js',
- chunkFileNames: 'assets/087AC4D233B64EB0[name].js',
- assetFileNames: 'assets/087AC4D233B64EB0[name].[ext]'
- }
- }
- const config = {
- base: './', // index.html文件所在位置
- root: './', // js导入的资源路径,src
- resolve: {
- alias
- },
- define: {
- 'process.env': {}
- },
- server: {
- // 如果使用docker-compose开发模式,设置为false
- open: true,
- port: process.env.VITE_CLI_PORT,
- proxy: {
- // IAM服务
- [process.env.VITE_BASE_API + '/iam']:{
- target: 'http://localhost:8080',
- changeOrigin: true,
- },
- // 把key的路径代理到target位置
- // detail: https://cli.vuejs.org/config/#devserver-proxy
- [process.env.VITE_BASE_API + '/cms']: {
- target: `${process.env.VITE_SERVICE_PATH}:${process.env.VITE_SERVICE_PORT}/`,
- changeOrigin: false,
- rewrite: path => path.replace(new RegExp('^'), '')
- },
- [process.env.VITE_BASE_API]: {
- // 需要代理的路径 例如 '/api'
- target: `${process.env.VITE_BASE_PATH}:${process.env.VITE_SERVER_PORT}/`, // 代理到 目标路径
- changeOrigin: false,
- rewrite: path =>
- path.replace(new RegExp('^' + process.env.VITE_BASE_API), '')
- }
- }
- },
- build: {
- minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
- manifest: false, // 是否产出manifest.json
- sourcemap: false, // 是否产出sourcemap.json
- outDir: 'dist', // 产出目录
- rollupOptions
- },
- esbuild,
- optimizeDeps,
- plugins: [
- process.env.VITE_POSITION === 'open' && GvaPositionServer(),
- process.env.VITE_POSITION === 'open' && GvaPosition(),
- legacyPlugin({
- targets: [
- 'Android > 39',
- 'Chrome >= 60',
- 'Safari >= 10.1',
- 'iOS >= 10.3',
- 'Firefox >= 54',
- 'Edge >= 15'
- ]
- }),
- vuePlugin(),
- svgBuilder('./src/assets/icons/'),
- [Banner(`\n Build based on gin-vue-admin \n Time : ${timestamp}`)]
- ],
- css: {
- preprocessorOptions: {
- scss: {
- additionalData: `@use "@/style/element/index.scss" as *;`
- }
- }
- }
- }
- if (NODE_ENV === 'development') {
- config.plugins.push(fullImportPlugin())
- } else {
- config.plugins.push(
- AutoImport({
- resolvers: [ElementPlusResolver()]
- }),
- Components({
- resolvers: [
- ElementPlusResolver({
- importStyle: 'sass'
- })
- ]
- })
- )
- }
- return config
- }
|