就可以發布單一檔案給個測試平台
不過有幾點需要注意
1.es6轉換
新版本的nodejs,可以直接運行es6
不過要使用pkg須先透過babel轉成es5
2.透過pkg設定將其他的檔案封裝到執行檔內
通常透過程式裡的require,會將相依的檔案封裝到
應用程式內
但若有其他如圖檔,css或其他js script要強制封裝進去
可以透過在package.json內設定pkg來載入
若設定了則需要透過pkg . 或 pkg package.json指令
讓pkg知道要另外封裝這些檔案
pkg網址
package.json檔案範例
{
"name": "simplesocket",
"version": "1.0.0",
"description": "build simple socket server excute file for web",
"main": "lib/index.js",
"bin": "lib/index.js",
"scripts": {
"start": "babel -s inline -d lib -w src | nodemon lib/index.js",
"build": "pkg package.json --target node8-macos-x64,node8-win-x86 --out-dir output",
"prepublish": "node_modules/babel-cli/bin/babel.js src --out-dir lib"
},
"babel": {
"presets": [
"es2015"
]
},
"pkg": {
"scripts":"node_modules/extra../**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ozzysun/simpleSocket.git"
},
"keywords": [
"socketio",
"express",
"pkg"
],
"author": "ozzysun",
"license": "ISC",
"bugs": {
"url": "https://github.com/ozzysun/simpleSocket/issues"
},
"homepage": "https://github.com/ozzysun/simpleSocket#readme",
"dependencies": {
...
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"nodemon": "^1.11.0"
}
}
沒有留言:
張貼留言