forked from zhouruizhe/gmTouringMiniApp
微信主包上限 2 MB,30 张 800×600 照片单独就 2.6 MB, 整包 3.2 MB,上传被拒(错误码 80051)。 按使用场景把照片拆成两层: - 主包缩略图 400×300 q75(678 KB),供地图、行程、打卡卡片使用, 这些场景最大只显示 192rpx(≈288 px @DPR3),800×600 是过剩 - 分包大图 800×600 q66(1832 KB),供详情页 hero 使用, 随 pages-poi 分包按需下载 两层都保持 4:3,PoiImage 的 aspectFill 行为不变,视觉表现与之前一致。 详情页从 pages/poi/detail 移到 pages-poi/detail:主包页面无法引用 分包资源,hero 要用大图,页面就必须在分包内。新增 coverPhotoFullUrlFor() 供分包内页面取大图,占位图仍指向主包。 verify-weixin-output.mjs 增加防回归检查:分包注册、两层照片数量 一致、主包与各分包实际体积(留 64 KB 余量)。包体再超限会在 verify 阶段失败,不必等上传才发现。 process-poi-photos.mjs 重写为双层产出,幂等,末尾报告包体占用并 在超限时退出非零。原图改从 src/photo-intake/ 读取(不提交仓库)。 改造后:主包 1522 KB、分包 pages-poi 1847 KB,均在 2048 KB 内。 mp-weixin 与 H5 均编译通过,97 个测试通过,vue-tsc 与 ESLint 无错。
99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
/// <reference types="vitest" />
|
||
import { resolve } from 'node:path'
|
||
import process from 'node:process'
|
||
import uni from '@dcloudio/vite-plugin-uni'
|
||
import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'
|
||
import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
|
||
import UniPages from '@uni-helper/vite-plugin-uni-pages'
|
||
import UnoCSS from 'unocss/vite'
|
||
import AutoImport from 'unplugin-auto-import/vite'
|
||
import Components from 'unplugin-vue-components/vite'
|
||
import { defineConfig } from 'vite'
|
||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||
|
||
// https://vitejs.dev/config/
|
||
export default defineConfig((configEnv) => {
|
||
return {
|
||
resolve: {
|
||
alias: [
|
||
{
|
||
find: '@',
|
||
replacement: resolve(__dirname, 'src'),
|
||
},
|
||
],
|
||
},
|
||
plugins: [
|
||
...(configEnv.command === 'serve'
|
||
&& configEnv.mode === 'development'
|
||
&& process.env.UNI_PLATFORM === 'h5'
|
||
? [vueDevTools()]
|
||
: []),
|
||
/**
|
||
* unocss
|
||
* @see https://github.com/antfu/unocss
|
||
* see unocss.config.ts for config
|
||
*/
|
||
UnoCSS(),
|
||
UniPages({
|
||
// 忽略页面内组件目录
|
||
exclude: ['**/components/**/*.*'],
|
||
// 点位详情页单独分包:它的 hero 大图(src/pages-poi/static/photos,约 1.8 MB)
|
||
// 随分包按需下载,否则主包会超微信 2 MB 上限。
|
||
subPackages: ['src/pages-poi'],
|
||
}),
|
||
/**
|
||
* unplugin-auto-import 按需 import
|
||
* @see https://github.com/antfu/unplugin-auto-import
|
||
*/
|
||
AutoImport({
|
||
imports: [
|
||
'vue',
|
||
'pinia',
|
||
'uni-app',
|
||
],
|
||
dts: true,
|
||
dirs: [
|
||
'./src/composables',
|
||
'./src/stores',
|
||
],
|
||
vueTemplate: true,
|
||
}),
|
||
/**
|
||
* vite-plugin-uni-layouts
|
||
* @see https://github.com/uni-helper/vite-plugin-uni-layouts
|
||
*/
|
||
UniLayouts(),
|
||
/**
|
||
* unplugin-vue-components 按需引入组件
|
||
* 注意:需注册至 uni 之前,否则不会生效
|
||
* @see https://github.com/antfu/vite-plugin-components
|
||
*/
|
||
Components({
|
||
dts: 'src/components.d.ts',
|
||
}),
|
||
/**
|
||
* 使用 TypeScript 编写 uni-app 的 manifest.json。
|
||
* @see https://github.com/uni-helper/vite-plugin-uni-manifest
|
||
*/
|
||
UniManifest(),
|
||
uni(),
|
||
{ // 自定义插件禁用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
|
||
},
|
||
},
|
||
],
|
||
/**
|
||
* Vitest
|
||
* @see https://github.com/vitest-dev/vitest
|
||
*/
|
||
test: {
|
||
environment: 'jsdom',
|
||
setupFiles: [resolve(__dirname, './test/setupTests.ts')],
|
||
},
|
||
}
|
||
})
|