美文网首页
vue打包部署app遇到问题解决笔记!

vue打包部署app遇到问题解决笔记!

作者: DragonersLi | 来源:发表于2021-12-03 23:27 被阅读0次

vue打包前端代码,修改配置:

vue.config.jspublicPathassetsDir/改成./

publicPath: './',   
assetsDir: "./",

src/router/index.jsmodehistory改成hash

const router = new VueRouter({
    mode: 'hash',
  //  base: '/h5/' //如果打包后在服务器是public下子目录,则要带上目录
    routes
})

HBuilder打包app:
新建5+App,输入名称和路径,选择默认模板创建
把生成的默认文件除了manifest.json全部删除,把打包后的vue代码放入
修改manifest.json配置,应用名称和图标等。
运行内置浏览器或者模拟器,真机等。macOS运行真机需开发者勾选

关于hbuilder打包app点击手机返回键直接退出app的解决:
main.js文件中加上一句:import './tools/appback.js'
其中appback.js来源网络,亲测android上有效,ios待验证!
`

/**
 * 解决hbuilder打包app之后点击手机返回键直接退出app的
 */
document.addEventListener('plusready', function () {
  var webview = plus.webview.currentWebview()
  plus.key.addEventListener('backbutton', function () {
    webview.canBack(function (e) {
      if (e.canBack) {
        webview.back()
      } else {
        // webview.close() //hide,quit
        // plus.runtime.quit()
        // 首页返回键处理
        // 处理逻辑:1秒内,连续两次按返回键,则退出应用;
        var first = null
        plus.key.addEventListener(
          'backbutton',
          function () {
            // 首次按键,提示‘再按一次退出应用’
            if (!first) {
              first = new Date().getTime()
              console.log('再按一次退出应用') // 此处可以用自定义提示
              setTimeout(function () {
                first = null
              }, 1000)
            } else {
              if (new Date().getTime() - first < 1500) {
                plus.runtime.quit()
              }
            }
          },
          false
        )
      }
    })
  })
})


问题:vue打包android后登陆一直转圈圈,抓包看不到报错信息
通过添加弹框提示,逐步调式。但HbuilderX打包有次数限制。换账号更换应用的标识AppID重新打包测试也没法定位问题根源。Charleshttps包,只看到登陆返回了token,后台接口日志也是看到有返回登录成功信息。就是没跳转。最后https://www.fundebug.com/登录账号拿到key,配置好运行app调式的同时,有报错就会在fundebug后台看到错误信息,同时邮件也会收到。

问题代码
Charles抓包 bug信息
fundebug收到的邮件信息

根据提示可知:由于项目中使用了async/await, 没有正确配置 babel,导致语法不支持、 报错Uncaught ReferenceError: regeneratorRuntime is not defined

那就安装这个包npm i --save-dev babel-plugin-transform-runtime又报其他错误!
npm i babel-polyfill -D还是一样报错,信息如下:
提取关键词继续搜If you are behind a proxy, please make sure that the 'proxy' config is set properly. See: 'npm help config'
日志记录里的报错关键词:npm ERR! code ECONNREFUSEDnpm ERR! errno ECONNREFUSED
npm安装任何包都报错的解决办法:
保证npm config get proxynpm config get https-proxy 两个命令的返回值都为null
不为null就设置为null:npm config set proxy nullnpm config set https-proxy null
非必须)清除npm中的代理和缓存npm config set proxy falsenpm cache clean --force
然后在执行命令就没有报错了。

PS D:\WorkSpace\wwwroot\thinkphp\jxtk20220324> npm i babel-polyfill -D
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/babel-polyfill failed, reason: connect ECONNREFUSED 127.0.0.1:1087
npm ERR!     at ClientRequest.<anonymous> (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\index.js:110:14)
npm ERR!     at ClientRequest.emit (node:events:390:28)
npm ERR!     at onerror (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR!  FetchError: request to https://registry.npmjs.org/babel-polyfill failed, reason: connect ECONNREFUSED 127.0.0.1:1087
npm ERR!     at ClientRequest.<anonymous> (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\index.js:110:14)
npm ERR!     at ClientRequest.emit (node:events:390:28)
npm ERR!     at onerror (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (C:\Users\DragonersLi\AppData\Roaming\npm\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5) {
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 1087,
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DragonersLi\AppData\Local\npm-cache\_logs\2022-04-01T03_17_38_269Z-debug-0.log
#关键步骤,代理设为null
PS D:\WorkSpace\wwwroot\thinkphp\jxtk20220324> npm config get proxy
null
PS D:\WorkSpace\wwwroot\thinkphp\jxtk20220324> npm config get https-proxy
http://127.0.0.1:1087/
PS D:\WorkSpace\wwwroot\thinkphp\jxtk20220324> npm config set https-proxy null
PS D:\WorkSpace\wwwroot\thinkphp\jxtk20220324> npm config get https-proxy     
null

安装npm i babel-polyfill -D 然后项目`src/main.js头部加入如下代码,解决了app登录一直转圈圈困扰两天的问题!

require('babel-polyfill');
import 'babel-polyfill';

相关文章

网友评论

      本文标题:vue打包部署app遇到问题解决笔记!

      本文链接:https://www.haomeiwen.com/subject/agizrxtx.html