123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import vue from '@vitejs/plugin-vue';
- import {resolve} from 'path';
- import {defineConfig, loadEnv, ConfigEnv} from 'vite';
- import vueSetupExtend from 'vite-plugin-vue-setup-extend';
- import legacy from '@vitejs/plugin-legacy';
- // @ts-ignore
- import AutoImport from 'unplugin-auto-import/vite'
- // @ts-ignore
- import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
- import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
- const pathResolve = (dir: string) => {
- return resolve(__dirname, '.', dir);
- };
- const alias: Record<string, string> = {
- '/@': pathResolve('./src/'),
- '@': pathResolve('./src'),
- 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
- };
- // @ts-ignore
- import config from "./src/utils/config.js"
- import * as path from "path";
- let prefixKeys = Object.keys(config).filter(i => i.includes('Prefix'))
- let proxyObj = prefixKeys.reduce((r, i) => {
- let prefix = config[i]
- r[prefix] = {
- target: config.proxyLocation + prefix,
- ws: true,
- changeOrigin: true,
- rewrite: (path: string) => path.replace(new RegExp('^' + prefix), ''),
- timeout: 10000000,
- }
- return r
- }, {})
- // @ts-ignore
- const viteConfig = defineConfig((mode: ConfigEnv) => {
- const env = loadEnv(mode.mode, process.cwd());
- return {
- plugins: [
- vue(),
- legacy({
- targets: ['since 2015'],
- additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // regenerator-runtime/runtime @dian/polyfill
- renderLegacyChunks: true,
- polyfills: [
- 'es.symbol',
- 'es.array.filter',
- 'es.promise',
- 'es.promise.finally',
- 'es/map',
- 'es/set',
- 'es.array.for-each',
- 'es.object.define-properties',
- 'es.object.define-property',
- 'es.object.get-own-property-descriptor',
- 'es.object.get-own-property-descriptors',
- 'es.object.keys',
- 'es.object.to-string',
- 'web.dom-collections.for-each',
- 'esnext.global-this',
- 'esnext.string.match-all',
- 'es.object.entries',
- 'es.object.from-entries',
- 'esnext.object.iterate-entries',
- ],
- modernPolyfills: ['es.string.replace-all'],
- }),
- vueSetupExtend(),
- AutoImport({
- imports: ['vue', 'vue-router', 'pinia'],
- resolvers: [
- ElementPlusResolver({
- importStyle: 'sass'
- })
- ],
- dts: false
- }),
- createSvgIconsPlugin({
- iconDirs: [path.resolve(process.cwd(), "src/assets/svg-icons")],//svg文件存放的路径
- symbolId: "icon-[name]",
- }),
- ],
- root: process.cwd(),
- resolve: {alias, extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']},
- base: mode.mode === 'development' ? '/' : '/mcp',
- optimizeDeps: {
- include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw', 'form-data', 'follow-redirects'],
- },
- server: {
- host: 'mcp.9n1m.com', // 真机模拟,使用
- // host: '127.0.0.1', // 真机模拟,使用
- port: 80,
- open: env.VITE_OPEN,
- hmr: true,
- proxy: proxyObj
- },
- build: {
- minify: 'terser',
- terserOptions: {
- compress: {
- drop_console: true,
- drop_debugger: true,
- },
- },
- outDir: 'dist',
- chunkSizeWarningLimit: 1500,
- rollupOptions: {
- output: {
- entryFileNames: `assets/[name].[hash].js`,
- chunkFileNames: `assets/[name].[hash].js`,
- assetFileNames: `assets/[name].[hash].[ext]`,
- compact: true,
- manualChunks: {
- vue: ['vue', 'vue-router', 'pinia'],
- echarts: ['echarts'],
- },
- },
- },
- },
- css: {
- preprocessorOptions: {
- css: {charset: false},
- preprocessorOptions: {
- scss: {
- additionalData: `@use "@/assets/styles/element/index.scss" as *;`,
- },
- },
- }
- },
- define: {
- __VUE_I18N_LEGACY_API__: JSON.stringify(false),
- __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
- __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
- __VERSION__: JSON.stringify(process.env.npm_package_version),
- },
- };
- });
- export default viteConfig;
|