[英]How can I just make sure that nodejs pkg is including all of my files? Executable runs in root folder but doesn't anywhere else
所以我有一個項目是 html 和 javascript。 您單擊 index.html 並在瀏覽器中打開 2D 模擬。 我想將 package 作為獨立的可執行文件 (.exe)。 我知道在得到建議之前還有其他方法,但如果可能的話,我想用節點來做這件事。
為了用節點觸發這個,我簡單地創建了一個執行'npm start'的app.js,它又執行'start index.html'。
當 pkg ( https://www.npmjs.com/package/pkg )只是一個純腳本時,我已經取得了巨大的成功,但是當我將此項目編譯為 exe 時,它將在瀏覽器中打開並正常工作。 問題是,如果我將可執行文件從原始文件夾(例如桌面)移動,它將不再起作用。 我想這是因為它不包括我需要的所有文件。
到目前為止,我已經嘗試了以下方法:
我用pkg. -t host
pkg. -t host
。
我試過用'glob'()包含所有文件,如下所示:
var glob = require( 'glob' )
, path = require( 'path' );
glob.sync( './html5/**/**/*.js' ).forEach( function( file ) {
require( path.resolve( file ) );
});
glob.sync( './html5/**/**/*.css' ).forEach( function( file ) {
require( path.resolve( file ) );
});
但這會返回有關 window 的錯誤(“未定義窗口”)。 我通過添加來解決這個問題:
if (typeof window !== "undefined") {
window.globalProvideData('stuff', 'more stuff');
}
每次我得到錯誤但最終它給了我我無法弄清楚的錯誤。
那么,如何包含所有文件,使其在根文件夾中的行為與它一樣?
編輯:這是文件夾結構和我的 package.json:
package.json:
{
"name": "test_story",
"version": "1.0.0",
"description": "testing story exe",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "start story.html"
},
"bin": "app.js",
"author": "",
"license": "ISC",
"dependencies": {
"glob": "^7.1.6",
"pkg": "^4.5.1"
},
"pkg": {
"assets": [
"html5/**/*",
"mobile/*.jpg",
"node_modules/**/*",
"story_content/**/*"
]
}
}
避免根文件夾的一個簡單技巧是運行為您啟動目錄的批處理文件。 此外,為確保所有文件都已正確傳輸,您可以檢查文件夾大小並進行比較。 這就是 FTP 經常工作的方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.