node,js,egg打包exe,跨平台


一直想實現打包的功能

終於網上有個靠譜的鏈接了:https://www.jianshu.com/p/02a6e99d7b94

but 按照文檔進行總是出現不能正常運行!!!

終於還是解決問題了,感謝:MrSmallLiu/pkg-egg-example 的作者的幫助!

環境:win10 ,node 8.16.1,npm-pkg 6.4.1 打包成 exe

1.上面鏈接基本上都可以完成打包exe

可能問題a:

⚠️  AssertionError [ERR_ASSERTION]: D:\snapshot\pkg-egg-example\package.json should exist
⚠️  Command Error, enable `DEBUG=common-bin` for detail
經過作者幫助,解決方法為:
在打包入口文件中加入:
console.log(__dirname) //打印所在的snapshot路徑,生產環境可以刪除
require(__dirname + '/node_modules/egg-scripts/bin/egg-scripts.js')

  

在命令行 直接運行 可以看的虛擬文件夾路徑
在啟動命令中 start 后面加上 路徑即可 
egg-demo.exe start D:\snapshot\src --port=7001 --title=egg-demo
基本可以正常運行了
可能問題b:
不能正常加載配置文件,驗證方法為 查看日志文件路徑是否修改成功
如果在 路徑是: c:\user\username\logs\title\ 則修改package.js文件
"scripts": [
      "./app/router.js",
      "./app.js",
      "./agent.js",
      "./package.json",
      "./config/**/*",
      "./app/controller/**/*",
      "./app/extend/**/*",
      "./app/schedule/**/*",
      "./app/service/**/*"
    ],
    "assets": [
      "./app/view/**/*",     
      "./app/public/**/*",
      "./static/**/*",
      "./node_modules/**/*"
    ]
tips:config.default.js 中
 
console.log('basedir:',appInfo.baseDir)//虛擬文件夾下的路徑
console.log('cur cwd:',curdir) //當前運行文件路徑 需要寫入的文件 使用此路徑 如日志
//如:
config.rundir =process.cwd()+ '/run';//這個必須添加 不然生成路由失敗:Internal Server Error, real status: 500

  

到此,我的項目已經可以正常運行了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM