From 2b3715f1610b4176d7abe33e34542389cef61853 Mon Sep 17 00:00:00 2001 From: zhuguifei <zhuguifei@zhuguifeideiMac.local> Date: 星期六, 12 四月 2025 17:12:22 +0800 Subject: [PATCH] Merge branch 'main' of http://lanpucloud.cn:1111/r/eims-master --- eims-ui-mobile/vite.config.ts | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 160 insertions(+), 0 deletions(-) diff --git a/eims-ui-mobile/vite.config.ts b/eims-ui-mobile/vite.config.ts new file mode 100644 index 0000000..f0fec23 --- /dev/null +++ b/eims-ui-mobile/vite.config.ts @@ -0,0 +1,160 @@ +import Uni from '@dcloudio/vite-plugin-uni' +import dayjs from 'dayjs' +import path from 'node:path' +import { defineConfig, loadEnv } from 'vite' +// @see https://uni-helper.js.org/vite-plugin-uni-pages +import UniPages from '@uni-helper/vite-plugin-uni-pages' +// @see https://uni-helper.js.org/vite-plugin-uni-layouts +import UniLayouts from '@uni-helper/vite-plugin-uni-layouts' +// @see https://github.com/uni-helper/vite-plugin-uni-platform +// 闇�瑕佷笌 @uni-helper/vite-plugin-uni-pages 鎻掍欢涓�璧蜂娇鐢� +import UniPlatform from '@uni-helper/vite-plugin-uni-platform' +// @see https://github.com/uni-helper/vite-plugin-uni-manifest +import UniManifest from '@uni-helper/vite-plugin-uni-manifest' +// @see https://unocss.dev/ +import { visualizer } from 'rollup-plugin-visualizer' +import UnoCSS from 'unocss/vite' +import AutoImport from 'unplugin-auto-import/vite' +import ViteRestart from 'vite-plugin-restart' +import { copyNativeRes } from './vite-plugins/copyNativeRes' + +// https://vitejs.dev/config/ +export default ({ command, mode }) => { + // console.log(mode === process.env.NODE_ENV) // true + + // mode: 鍖哄垎鐢熶骇鐜杩樻槸寮�鍙戠幆澧� + console.log('command, mode -> ', command, mode) + // pnpm dev:h5 鏃跺緱鍒� => serve development + // pnpm build:h5 鏃跺緱鍒� => build production + // pnpm dev:mp-weixin 鏃跺緱鍒� => build development (娉ㄦ剰鍖哄埆锛宑ommand涓篵uild) + // pnpm build:mp-weixin 鏃跺緱鍒� => build production + // pnpm dev:app 鏃跺緱鍒� => build development (娉ㄦ剰鍖哄埆锛宑ommand涓篵uild) + // pnpm build:app 鏃跺緱鍒� => build production + // dev 鍜� build 鍛戒护鍙互鍒嗗埆浣跨敤 .env.development 鍜� .env.production 鐨勭幆澧冨彉閲� + + const { UNI_PLATFORM } = process.env + console.log('UNI_PLATFORM -> ', UNI_PLATFORM) // 寰楀埌 mp-weixin, h5, app 绛� + + const env = loadEnv(mode, path.resolve(process.cwd(), 'env')) + const { + VITE_APP_PORT, + VITE_SERVER_BASEURL, + VITE_DELETE_CONSOLE, + VITE_SHOW_SOURCEMAP, + VITE_APP_PROXY, + VITE_APP_PROXY_PREFIX, + } = env + console.log('鐜鍙橀噺 env -> ', env) + + return defineConfig({ + envDir: './env', // 鑷畾涔塭nv鐩綍 + + plugins: [ + UniPages({ + exclude: ['**/components/**/**.*'], + routeBlockLang: 'json5', // 铏界劧璁句簡榛樿鍊硷紝浣嗘槸vue鏂囦欢杩樻槸瑕佸姞涓� lang="json5", 杩欐牱鎵嶈兘寰堝ソ鍦版牸寮忓寲 + // homePage 閫氳繃 vue 鏂囦欢鐨� route-block 鐨則ype="home"鏉ヨ瀹� + // pages 鐩綍涓� src/pages锛屽垎鍖呯洰褰曚笉鑳介厤缃湪pages鐩綍涓� + // subPackages: ['src/pages-sub'], // 鏄釜鏁扮粍锛屽彲浠ラ厤缃涓紝浣嗘槸涓嶈兘涓簆ages閲岄潰鐨勭洰褰� + dts: 'src/types/uni-pages.d.ts', + }), + UniLayouts(), + UniPlatform(), + UniManifest(), + // UniXXX 闇�瑕佸湪 Uni 涔嬪墠寮曞叆 + Uni(), + { + // 涓存椂瑙e喅 dcloudio 瀹樻柟鐨� @dcloudio/uni-mp-compiler 鍑虹幇鐨勭紪璇� BUG + // 鍙傝�� github issue: https://github.com/dcloudio/uni-app/issues/4952 + // 鑷畾涔夋彃浠剁鐢� vite:vue 鎻掍欢鐨� devToolsEnabled锛屽己鍒剁紪璇� vue 妯℃澘鏃� inline 涓� true + name: 'fix-vite-plugin-vue', + configResolved(config) { + const plugin = config.plugins.find((p) => p.name === 'vite:vue') + if (plugin && plugin.api && plugin.api.options) { + plugin.api.options.devToolsEnabled = false + } + }, + }, + UnoCSS(), + AutoImport({ + imports: ['vue', 'uni-app'], + dts: 'src/types/auto-import.d.ts', + dirs: ['src/hooks'], // 鑷姩瀵煎叆 hooks + eslintrc: { enabled: true }, + vueTemplate: true, // default false + }), + + ViteRestart({ + // 閫氳繃杩欎釜鎻掍欢锛屽湪淇敼vite.config.js鏂囦欢鍒欎笉闇�瑕侀噸鏂拌繍琛屼篃鐢熸晥閰嶇疆 + restart: ['vite.config.js'], + }), + // h5鐜澧炲姞 BUILD_TIME 鍜� BUILD_BRANCH + UNI_PLATFORM === 'h5' && { + name: 'html-transform', + transformIndexHtml(html) { + return html.replace('%BUILD_TIME%', dayjs().format('YYYY-MM-DD HH:mm:ss')) + }, + }, + // 鎵撳寘鍒嗘瀽鎻掍欢锛宧5 + 鐢熶骇鐜鎵嶅脊鍑� + UNI_PLATFORM === 'h5' && + mode === 'production' && + visualizer({ + filename: './node_modules/.cache/visualizer/stats.html', + open: true, + gzipSize: true, + brotliSize: true, + }), + // 鍙湁鍦� app 骞冲彴鏃舵墠鍚敤 copyNativeRes 鎻掍欢 + UNI_PLATFORM === 'app' && copyNativeRes(), + ], + define: { + __UNI_PLATFORM__: JSON.stringify(UNI_PLATFORM), + __VITE_APP_PROXY__: JSON.stringify(VITE_APP_PROXY), + }, + css: { + postcss: { + plugins: [ + // autoprefixer({ + // // 鎸囧畾鐩爣娴忚鍣� + // overrideBrowserslist: ['> 1%', 'last 2 versions'], + // }), + ], + }, + }, + + resolve: { + alias: { + '@': path.join(process.cwd(), './src'), + '@img': path.join(process.cwd(), './src/static/images'), + }, + }, + server: { + host: '0.0.0.0', + hmr: true, + port: Number.parseInt(VITE_APP_PORT, 10), + // 浠� H5 绔敓鏁堬紝鍏朵粬绔笉鐢熸晥锛堝叾浠栫璧癰uild锛屼笉璧癲evServer) + proxy: JSON.parse(VITE_APP_PROXY) + ? { + [VITE_APP_PROXY_PREFIX]: { + target: VITE_SERVER_BASEURL, + changeOrigin: true, + rewrite: (path) => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''), + }, + } + : undefined, + }, + build: { + // 鏂逛究闈瀐5绔皟璇� + sourcemap: VITE_SHOW_SOURCEMAP === 'true', // 榛樿鏄痜alse + target: 'es6', + // 寮�鍙戠幆澧冧笉鐢ㄥ帇缂� + minify: mode === 'development' ? false : 'terser', + terserOptions: { + compress: { + drop_console: VITE_DELETE_CONSOLE === 'true', + drop_debugger: true, + }, + }, + }, + }) +} -- Gitblit v1.9.3