多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# uniapp打包 ## H5 1、替换特定变量 ![](https://img.kancloud.cn/24/25/24255a21aa56b8570155582552506e26_547x645.png) ``` siteId: '{{$siteId}}', 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、清空微信小程序AppId ![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png) # 4、设置完成后点击发行发行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) # 更改路由,搜索 **__uniConfig.router** ,找到base字段,将值替换成:**base: "/h5/s"+ m[1] +"/"** 如图: ![](https://img.kancloud.cn/d0/cc/d0cc27f225f92f1249dda410ae3e39d7_542x80.png) 往上滑,找到函数开始位置,增加以下代码: ![](https://img.kancloud.cn/a4/92/a492f09ab5eb4c74bef2ae8f58489ba0_885x195.png) ``` m = location.href.match(/\/s(\d*)\//); if (!m) throw 'Illegal request'; ``` 代码每次都是随机生成的,如果找不到就参考示例代码,找相似的代码: ``` e130: function(e, n, t) { "use strict"; (function(e) { var n = t("ee27"), o = n(t("e143")), m = location.href.match(/\/s(\d*)\//); if (!m) throw 'Illegal request'; e["____B8CA6D8____"] = !0, delete e["____B8CA6D8____"], e.__uniConfig = { globalStyle: { navigationBarTextStyle: "black", navigationBarTitleText: "", navigationBarBackgroundColor: "#ffffff", backgroundColor: "#F7f7f7", backgroundColorTop: "#f7f7f7", backgroundColorBottom: "#f7f7f7" } }, e.__uniConfig.router = { mode: "history", base: "/h5/s"+ m[1] +"/" }, ``` # 5、根目录压缩 ![](https://img.kancloud.cn/d6/e2/d6e284657bb782976ac97a16bae1b43d_707x152.png) # ## weapp 1、替换特定变量 ![](https://img.kancloud.cn/24/25/24255a21aa56b8570155582552506e26_547x645.png) ``` siteId: '{{$siteId}}', baseUrl: "{{$baseUrl}}", imgDomain: "{{$imgDomain}}", h5Domain: "{{$h5Domain}}", mpKey: "{{$mpKey}}", apiSecurity: Boolean(parseInt('{{$apiSecurity}}')), publicKey: `{{$publicKey}}` ``` # 2、清空微信小程序AppId ![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png) # 3、编译微信小程序代码 ![](https://img.kancloud.cn/c1/1b/c11be2a76f10aa7af81437b35c66e7d9_871x455.png) # 4、打开unpackage\dist\dev\mp-weixin目录 ![](https://img.kancloud.cn/d6/46/d646e6fa5f78afc58d645231c547161a_382x183.png) ![](https://img.kancloud.cn/81/25/81257bfcaa328598e00a4a0ac1ef9f6c_725x327.png) # 5、打开common/vendor.js,搜索 “{{$publicKey}}”,替换引号 ![](https://img.kancloud.cn/91/51/9151db38f9d4c44b65d7815938de836a_1500x306.png) 6、根目录压缩 ![](https://img.kancloud.cn/e4/07/e4076ba9109b262b2cfbfd0f8b0d211e_738x344.png) # ## 源码 1、清空config.js配置 ![](https://img.kancloud.cn/4a/79/4a7962604a6f900fb7c7e896f80935bd_319x558.png) # 2、清空微信小程序AppId ![](https://img.kancloud.cn/fd/5c/fd5cb42e12f9f5ad7160f99201e8cfeb_933x669.png) # 3、删除unpackage文件夹 # 4、根目录压缩 ![](https://img.kancloud.cn/ee/67/ee67571e65eb4b233a5737b67fbf668e_648x403.png)