[英]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
So I have a project that is html and javascript.所以我有一个项目是 html 和 javascript。 You click index.html and it opens a 2D simulation in the browser.
您单击 index.html 并在浏览器中打开 2D 模拟。 I'd like to package this as a standalone executable (.exe).
我想将 package 作为独立的可执行文件 (.exe)。 I know there are other methods before I get suggestions but I want to do this with node, if possible.
我知道在得到建议之前还有其他方法,但如果可能的话,我想用节点来做这件事。
To trigger this with node I've simply created an app.js that executes 'npm start', which in turn executes 'start index.html'.为了用节点触发这个,我简单地创建了一个执行'npm start'的app.js,它又执行'start index.html'。
I've had great success with pkg ( https://www.npmjs.com/package/pkg ) when its just a pure script but when I compile this project as an exe it WILL open in the browser and work fine.当 pkg ( https://www.npmjs.com/package/pkg )只是一个纯脚本时,我已经取得了巨大的成功,但是当我将此项目编译为 exe 时,它将在浏览器中打开并正常工作。 Issue is if I then move the executable from the original folder (eg to the desktop) it no longer works.
问题是,如果我将可执行文件从原始文件夹(例如桌面)移动,它将不再起作用。 I imagine this is because it is not including all of the files I need.
我想这是因为它不包括我需要的所有文件。
So far I have tried the following:到目前为止,我已经尝试了以下方法:
I compile with pkg. -t host
我用
pkg. -t host
pkg. -t host
. pkg. -t host
。
I've tried including all files with 'glob'(), like so:我试过用'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 ) );
});
But this returns an error regarding window ('window is not defined').但这会返回有关 window 的错误(“未定义窗口”)。 I worked around this by adding:
我通过添加来解决这个问题:
if (typeof window !== "undefined") {
window.globalProvideData('stuff', 'more stuff');
}
every time I got the error but eventually it was giving me errors I can't figure out.每次我得到错误但最终它给了我我无法弄清楚的错误。
So, how can I include all files so it behaves as it does while in the root folder?那么,如何包含所有文件,使其在根文件夹中的行为与它一样?
EDIT: Here's the folder structure and my package.json:编辑:这是文件夹结构和我的 package.json:
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/**/*"
]
}
}
One simple trick to avoid the root folder would be to run batch files that launch your directories for you.避免根文件夹的一个简单技巧是运行为您启动目录的批处理文件。 Also, to insure all files have been transferred correctly you could check the folder size and compare.
此外,为确保所有文件都已正确传输,您可以检查文件夹大小并进行比较。 This is how FTP often works.
这就是 FTP 经常工作的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.