github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/vite.config.ts (about) 1 import {resolve} from 'path' 2 import type {ConfigEnv, UserConfig} from 'vite' 3 import {loadEnv} from 'vite' 4 import Vue from '@vitejs/plugin-vue' 5 import VueJsx from '@vitejs/plugin-vue-jsx' 6 import WindiCSS from 'vite-plugin-windicss' 7 import progress from 'vite-plugin-progress' 8 import EslintPlugin from 'vite-plugin-eslint' 9 import {ViteEjsPlugin} from "vite-plugin-ejs" 10 import PurgeIcons from 'vite-plugin-purge-icons' 11 import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite" 12 import {createSvgIconsPlugin} from 'vite-plugin-svg-icons' 13 import DefineOptions from "unplugin-vue-define-options/vite" 14 import {createStyleImportPlugin, ElementPlusResolve} from 'vite-plugin-style-import' 15 import Unfonts from 'unplugin-fonts/vite' 16 import analyze from "rollup-plugin-analyzer"; 17 import {VitePWA, VitePWAOptions} from 'vite-plugin-pwa' 18 import process from "node:process"; 19 20 // https://vitejs.dev/config/ 21 const root = process.cwd() 22 23 function pathResolve(dir: string) { 24 return resolve(root, '.', dir) 25 } 26 27 const pwaOptions: Partial<VitePWAOptions> = { 28 mode: 'production', 29 base: '/', 30 includeAssets: ['*.svg', '*.png', '*.xml', '*.ico'], 31 manifest: { 32 id: '36b70975-9daf-4ea0-a451-340ab66fc175', 33 orientation: 'any', 34 name: "Smart Home", 35 short_name: "Smart Home", 36 description: "Software package for automation", 37 start_url: "/", 38 display: "standalone", 39 background_color: "#333335", 40 theme_color: "#333335", 41 icons: [ 42 { 43 "src": "/android-chrome-64x64.png", 44 "type": "image/png", 45 "sizes": "64x64" 46 }, 47 { 48 "src": "/android-chrome-192x192.png", 49 "type": "image/png", 50 "sizes": "192x192" 51 }, 52 { 53 src: '/android-chrome-512x512.png', 54 sizes: '512x512', 55 type: 'image/png', 56 }, 57 { 58 src: '/maskable-icon.png', 59 sizes: '512x512', 60 type: 'image/png', 61 purpose: 'maskable' 62 } 63 ], 64 }, 65 66 registerType: 'autoUpdate', 67 68 strategies: 'injectManifest', 69 injectManifest: { 70 rollupFormat: 'iife', 71 maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, 72 }, 73 74 // add this to cache all the imports 75 workbox: { 76 maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, 77 }, 78 } 79 80 export default ({command, mode}: ConfigEnv): UserConfig => { 81 let env = {} as any 82 const isBuild = command === 'build' 83 if (!isBuild) { 84 env = loadEnv((process.argv[3] === '--mode' ? process.argv[4] : process.argv[3]), root) 85 } else { 86 env = loadEnv(mode, root) 87 } 88 return { 89 base: env.VITE_BASE_PATH, 90 plugins: [ 91 Vue(), 92 VueJsx(), 93 WindiCSS(), 94 progress(), 95 Unfonts({}), 96 createStyleImportPlugin({ 97 resolves: [ElementPlusResolve()], 98 libs: [{ 99 libraryName: 'element-plus', 100 esModule: true, 101 resolveStyle: (name) => { 102 return `element-plus/es/components/${name.substring(3)}/style/css` 103 } 104 }] 105 }), 106 EslintPlugin({ 107 cache: false, 108 include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件 109 }), 110 VueI18nPlugin({ 111 runtimeOnly: true, 112 compositionOnly: true, 113 include: [resolve(__dirname, 'src/locales/**')] 114 }), 115 createSvgIconsPlugin({ 116 iconDirs: [pathResolve('src/assets/svgs')], 117 symbolId: 'icon-[dir]-[name]', 118 svgoOptions: true 119 }), 120 PurgeIcons(), 121 DefineOptions(), 122 ViteEjsPlugin({ 123 title: env.VITE_APP_TITLE 124 }), 125 // virtualMessagePlugin(), 126 VitePWA(pwaOptions), 127 ], 128 129 css: { 130 preprocessorOptions: { 131 less: { 132 additionalData: '@import "./src/styles/variables.module.less";', 133 javascriptEnabled: true 134 } 135 } 136 }, 137 resolve: { 138 extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.less', '.css'], 139 alias: [ 140 { 141 find: 'vue-i18n', 142 replacement: 'vue-i18n/dist/vue-i18n.cjs.js' 143 }, 144 { 145 find: /\@\//, 146 replacement: `${pathResolve('src')}/` 147 } 148 ] 149 }, 150 build: { 151 minify: 'terser', 152 outDir: env.VITE_OUT_DIR || 'dist', 153 sourcemap: env.VITE_SOURCEMAP === 'true' ? 'inline' : false, 154 // brotliSize: false, 155 terserOptions: { 156 compress: { 157 drop_debugger: env.VITE_DROP_DEBUGGER === 'true', 158 drop_console: env.VITE_DROP_CONSOLE === 'true' 159 } 160 }, 161 rollupOptions: { 162 plugins: [analyze()] 163 }, 164 }, 165 server: { 166 port: 9527, 167 proxy: { 168 // 选项写法 169 '/api': { 170 target: 'http://127.0.0.1:8000', 171 changeOrigin: true, 172 rewrite: path => path.replace(/^\/api/, '') 173 } 174 }, 175 hmr: { 176 overlay: false 177 }, 178 host: '0.0.0.0' 179 }, 180 optimizeDeps: { 181 include: [ 182 'vue', 183 'vue-router', 184 'vue-types', 185 'element-plus/es/locale/lang/zh-cn', 186 'element-plus/es/locale/lang/en', 187 '@iconify/iconify', 188 '@vueuse/core', 189 'axios', 190 'qs', 191 'echarts', 192 'echarts-wordcloud', 193 'intro.js', 194 'qrcode', 195 ] 196 }, 197 198 } 199 }