# uniapp打包
## H5
1、替换特定变量
![](https://img.kancloud.cn/58/64/5864b679cd956d59ac95b0e837071094_532x700.png)
```
baseUrl: "{{$baseUrl}}",
imgDomain: "{{$imgDomain}}",
h5Domain: "{{$h5Domain}}",
mpKey: "{{$mpKey}}",
apiSecurity: Boolean(parseInt('{{$apiSecurity}}')),
publicKey: `{{$publicKey}}`
```
#
2、HBuilder中选择发行-网站H5手机版![](https://img.kancloud.cn/38/e2/38e2c66dfc8c3dda05622911a636012d_652x429.png)
点击高级进行发布配置
![](https://img.kancloud.cn/75/7e/757ed4c60d4e0c65c65fe3b9d52d039a_593x257.png)
![](https://img.kancloud.cn/56/43/564356132a01bac44386203584f1b59c_831x446.png)
#
3、设置完成后点击发行h5,编译完成之后进入编译目录 打开 static/js目录下的**index.xxxxxx.js**文件
[代码格式化工具](http://tool.chinaz.com/tools/jsformat.aspx?qq-pf-to=pcqq.c2c)
![![](https://img.kancloud.cn/f5/39/f539972557b2b90a5d7b9ddac187c62f_343x65.png)](images/screenshot_1601259370201.png)
打开该js后格式化文件搜索 “{{$publicKey}}” ,替换引号
![](https://img.kancloud.cn/25/3b/253b0f08f6c7ba464951db6709cd05b0_792x230.png)
#
4、清空微信小程序AppId
![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png)
#
5、根目录压缩
![](https://img.kancloud.cn/d6/e2/d6e284657bb782976ac97a16bae1b43d_707x152.png)
#
## weapp
1、编译微信小程序代码
![](https://img.kancloud.cn/c1/1b/c11be2a76f10aa7af81437b35c66e7d9_871x455.png)
#
2、打开unpackage\dist\dev\mp-weixin目录
![](https://img.kancloud.cn/d6/46/d646e6fa5f78afc58d645231c547161a_382x183.png)
![](https://img.kancloud.cn/81/25/81257bfcaa328598e00a4a0ac1ef9f6c_725x327.png)
#
3、打开common/vendor.js,搜索 “{{$publicKey}}”,替换引号
![](https://img.kancloud.cn/91/51/9151db38f9d4c44b65d7815938de836a_1500x306.png)
4、清空微信小程序AppId
![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png)
#
5、根目录压缩
![](https://img.kancloud.cn/e4/07/e4076ba9109b262b2cfbfd0f8b0d211e_738x344.png)
#
## 源码
1、清空config.js配置
![](https://img.kancloud.cn/9e/62/9e62996c79cdce46e1e1781b3f92a96b_596x721.png)
#
2、清空微信小程序AppId
![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png)
#
3、删除unpackage文件夹
#
4、根目录压缩
![](https://img.kancloud.cn/ee/67/ee67571e65eb4b233a5737b67fbf668e_648x403.png)