peixue-dev/Archive/[一次性]小程序主包优化说明-2026-01-31.md

67 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 小程序主包优化说明
## 问题
- 主包大小5.8MB
- 微信限制2MB
- 原因static目录图片约2MB
## 快速解决方案
### 方案A临时删除图片立即可上传
1. 删除 static/banner 和 static/button 下的所有图片
2. 主包立即减少 2MB
3. 可以先上传小程序
4. 后续再添加网络图片
### 方案B使用网络图片推荐
1. 将图片上传到你的服务器
2. 修改代码使用网络地址
3. 例如:`https://your-domain.com/images/banner1.jpg`
## 执行步骤
### 立即执行方案A
```bash
# 运行批处理文件
Archive\[一次性]小程序主包快速优化-2026-01-31.bat
```
### 修改代码使用网络图片方案B
修改 `peidu/uniapp/src/pages/index/components/UserHome.vue`:
```javascript
// 原来
bannerList: [
{ id: 1, image: '/static/banner/banner1.jpg' },
...
],
// 修改为
bannerList: [
{ id: 1, image: 'https://your-domain.com/images/banner1.jpg' },
...
],
```
## 建议
**立即执行方案A**,这样你可以:
1. 马上上传小程序
2. 后续慢慢优化图片方案
3. 不影响功能(只是暂时没有图片)
## 长期方案
1. **使用CDN**: 将所有静态资源放到CDN
2. **图片懒加载**: 按需加载图片
3. **WebP格式**: 使用更小的图片格式
4. **后端API**: 从后端获取轮播图数据
## 需要确认
你想执行哪个方案?
- A: 立即删除图片(可以马上上传)
- B: 我帮你修改代码使用网络图片需要你提供图片URL
- C: 两者都做(先删除,后续再添加网络图片)