如何在 Windows 上打包 NW.js 应用程序
How to package a NW.js application on Windows
I am reading the instructions for how to package a NW.js app 措辞混乱,毫无意义。我突出显示了矛盾的单词沙拉部分。
Create a zip file (this is built into XP, Vista and 7) Copy all of
your files into the zip file, retaining directory structure and making
sure that the package.json file is in the root directory (if you make
a zip file containing a folder with your stuff in it, then it's not
going to work) Rename the file extension from .zip to .nw. By default,
file extensions may be hidden. You need to (press alt), go to folder
options and uncheck "Hide extensions for known file types" to be able
to rename the zip.
是否有关于如何执行此操作的简单分步说明集?
我上网查了一下,找不到 Windows OS。目标是创建一个可执行文件 ( .exe ),其中应用程序的内部结构对用户隐藏。
我以前在 Mac 上做过,但从来没有 windows。官方文档写的太乱了,到处都是,我看不懂。
为此,您可以使用 https://github.com/nwjs/nw-builder
Lets you build your NW.js apps for mac, win and linux via cli. It will
download the prebuilt binaries for a newest version, unpacks it,
creates a release folder, create the app.nw file for a specified
directory and copies the app.nw file where it belongs.
首先,使用全局安装node-webkit-builder模块:
$ npm install node-webkit-builder -g
安装模块后,您可以运行 nwbuild 命令如下:
$ nwbuild [options] [path]
而路径是项目文件夹的路径,选项是以下代码中描述的选项:
-p Operating System to build ['osx32', 'osx64', 'win32', 'win64']
-v NW.js version [default: "latest"]
-r Runs NW.js project [default: false]
-o The path of the output folder [default: "./build"]
-f Force download of node-webkit [default: false]
--quiet Disables logging
一些例子:
运行一个项目(当前平台):
$ nwbuild -v [version of your nw.js] -r /path/to/the/project
为 Win32 or/and Win64 平台构建项目(可执行文件 ( .exe )):
$ nwbuild -v [version of your nw.js] -p win32,win64 /path/to/the/project
If your cmd currently open in the project folder, instread write full
path to your project you can just use dot symbol
欢迎您使用我的自动批处理文件。它编译、更新要包含的所有文件的时间戳,并运行您的应用程序进行测试。
在 XP 或 W7 下完美运行。
注意:只需根据需要搜索并替换 "SourceDir"、"DestinDir" 和 "ProgName" 的所有实例。
@echo off
title ProgName Compile & Run Script (c) 2016
cls
set FILETOZIP=C:\SourceDir\*.*
set TEMPDIR=C:\temp
: rmdir %TEMPDIR%
mkdir %TEMPDIR%
xcopy /s %FILETOZIP% %TEMPDIR%
cd C:\temp
copy /b *.* +,,
cd C:\DestinDir
echo Set objArgs = WScript.Arguments > Temp.vbs
echo InputFolder = objArgs(0) >> Temp.vbs
echo ZipFile = objArgs(1) >> Temp.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> Temp.vbs
echo Set objShell = CreateObject("Shell.Application") >> Temp.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> Temp.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> Temp.vbs
echo wScript.Sleep 2000 >> Temp.vbs
del C:\DestinDir\ProgName.exe /f /s
CScript Temp.vbs %TEMPDIR% C:\DestinDir\ProgName.zip
ren C:\DestinDir\ProgName.zip ProgName.nw
copy /b nw.exe+ProgName.nw ProgName.exe
del C:\DestinDir\Temp.vbs /f /s
del C:\DestinDir\ProgName.nw /f /s
rmdir C:\temp /s /q
start ProgName.exe
nw-builder does not support the NW.js newest versions (version > 0.12) before the 02/July/2016 release,现在有支持了,但是还是alpha/beta状态。
您可以尝试使用 nwjs-builder,简单而强大(通过 withFFmpeg
选项预构建 ffmpeg 支持),如果您想将其用作一个模块并自动构建(例如)使用 gulp
,你可以这样做:
var gulp = require('gulp'),
glp = require('gulp-load-plugins')(),
del = require('del'),
nwb = require('nwjs-builder'),
argv = require('yargs').alias('p', 'platforms').argv,
paths = {
build: './build',
src: './src',
images: './src/images'
},
detectCurrentPlatform = function () {
switch (process.platform) {
case 'darwin':
return process.arch === 'x64' ? 'osx64' : 'osx32';
case 'win32':
return (process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) ? 'win64' : 'win32';
case 'linux':
return process.arch === 'x64' ? 'linux64' : 'linux32';
}
};
gulp.task('build', ['clean:build'], function () {
return new Promise(function (resolve, reject) {
nwb.commands.nwbuild(paths.src, {
version: '0.15.4',
platforms: argv.p ? argv.p : detectCurrentPlatform(),
withFFmpeg: true,
production: true,
macIcns: paths.images + '/icon.icns',
winIco: paths.images + '/icon.ico',
sideBySide: false,
//outputFormat: 'ZIP',
outputDir: paths.build
}, function (err) {
if (err) {
reject(err);
}
return resolve();
});
});
});
gulp.task('clean:build', function () {
return gulp.src(paths.build, {
read: false
}).pipe(glp.clean());
});
您的清单中需要的依赖项(调整您想要的版本):
"devDependencies": {
"del": "^2.2.1",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-load-plugins": "^1.2.4",
"nwjs-builder": "latest",
"yargs": "^4.7.1"
}
您可以在主要 GitHub 存储库中获得更多关于使用和参数的文档。
I am reading the instructions for how to package a NW.js app 措辞混乱,毫无意义。我突出显示了矛盾的单词沙拉部分。
Create a zip file (this is built into XP, Vista and 7) Copy all of your files into the zip file, retaining directory structure and making sure that the package.json file is in the root directory (if you make a zip file containing a folder with your stuff in it, then it's not going to work) Rename the file extension from .zip to .nw. By default, file extensions may be hidden. You need to (press alt), go to folder options and uncheck "Hide extensions for known file types" to be able to rename the zip.
是否有关于如何执行此操作的简单分步说明集? 我上网查了一下,找不到 Windows OS。目标是创建一个可执行文件 ( .exe ),其中应用程序的内部结构对用户隐藏。
我以前在 Mac 上做过,但从来没有 windows。官方文档写的太乱了,到处都是,我看不懂。
为此,您可以使用 https://github.com/nwjs/nw-builder
Lets you build your NW.js apps for mac, win and linux via cli. It will download the prebuilt binaries for a newest version, unpacks it, creates a release folder, create the app.nw file for a specified directory and copies the app.nw file where it belongs.
首先,使用全局安装node-webkit-builder模块:
$ npm install node-webkit-builder -g
安装模块后,您可以运行 nwbuild 命令如下:
$ nwbuild [options] [path]
而路径是项目文件夹的路径,选项是以下代码中描述的选项:
-p Operating System to build ['osx32', 'osx64', 'win32', 'win64']
-v NW.js version [default: "latest"]
-r Runs NW.js project [default: false]
-o The path of the output folder [default: "./build"]
-f Force download of node-webkit [default: false]
--quiet Disables logging
一些例子:
运行一个项目(当前平台):
$ nwbuild -v [version of your nw.js] -r /path/to/the/project
为 Win32 or/and Win64 平台构建项目(可执行文件 ( .exe )):
$ nwbuild -v [version of your nw.js] -p win32,win64 /path/to/the/project
If your cmd currently open in the project folder, instread write full path to your project you can just use dot symbol
欢迎您使用我的自动批处理文件。它编译、更新要包含的所有文件的时间戳,并运行您的应用程序进行测试。
在 XP 或 W7 下完美运行。
注意:只需根据需要搜索并替换 "SourceDir"、"DestinDir" 和 "ProgName" 的所有实例。
@echo off
title ProgName Compile & Run Script (c) 2016
cls
set FILETOZIP=C:\SourceDir\*.*
set TEMPDIR=C:\temp
: rmdir %TEMPDIR%
mkdir %TEMPDIR%
xcopy /s %FILETOZIP% %TEMPDIR%
cd C:\temp
copy /b *.* +,,
cd C:\DestinDir
echo Set objArgs = WScript.Arguments > Temp.vbs
echo InputFolder = objArgs(0) >> Temp.vbs
echo ZipFile = objArgs(1) >> Temp.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> Temp.vbs
echo Set objShell = CreateObject("Shell.Application") >> Temp.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> Temp.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> Temp.vbs
echo wScript.Sleep 2000 >> Temp.vbs
del C:\DestinDir\ProgName.exe /f /s
CScript Temp.vbs %TEMPDIR% C:\DestinDir\ProgName.zip
ren C:\DestinDir\ProgName.zip ProgName.nw
copy /b nw.exe+ProgName.nw ProgName.exe
del C:\DestinDir\Temp.vbs /f /s
del C:\DestinDir\ProgName.nw /f /s
rmdir C:\temp /s /q
start ProgName.exe
nw-builder does not support the NW.js newest versions (version > 0.12) before the 02/July/2016 release,现在有支持了,但是还是alpha/beta状态。
您可以尝试使用 nwjs-builder,简单而强大(通过 withFFmpeg
选项预构建 ffmpeg 支持),如果您想将其用作一个模块并自动构建(例如)使用 gulp
,你可以这样做:
var gulp = require('gulp'),
glp = require('gulp-load-plugins')(),
del = require('del'),
nwb = require('nwjs-builder'),
argv = require('yargs').alias('p', 'platforms').argv,
paths = {
build: './build',
src: './src',
images: './src/images'
},
detectCurrentPlatform = function () {
switch (process.platform) {
case 'darwin':
return process.arch === 'x64' ? 'osx64' : 'osx32';
case 'win32':
return (process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) ? 'win64' : 'win32';
case 'linux':
return process.arch === 'x64' ? 'linux64' : 'linux32';
}
};
gulp.task('build', ['clean:build'], function () {
return new Promise(function (resolve, reject) {
nwb.commands.nwbuild(paths.src, {
version: '0.15.4',
platforms: argv.p ? argv.p : detectCurrentPlatform(),
withFFmpeg: true,
production: true,
macIcns: paths.images + '/icon.icns',
winIco: paths.images + '/icon.ico',
sideBySide: false,
//outputFormat: 'ZIP',
outputDir: paths.build
}, function (err) {
if (err) {
reject(err);
}
return resolve();
});
});
});
gulp.task('clean:build', function () {
return gulp.src(paths.build, {
read: false
}).pipe(glp.clean());
});
您的清单中需要的依赖项(调整您想要的版本):
"devDependencies": {
"del": "^2.2.1",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-load-plugins": "^1.2.4",
"nwjs-builder": "latest",
"yargs": "^4.7.1"
}
您可以在主要 GitHub 存储库中获得更多关于使用和参数的文档。