MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度分析nwutils/Web2Executable:将Web应用打包为原生应用的利器

项目背景与痛点

现代Web应用的功能越来越强大,它们能实现之前只有原生应用才有的复杂业务流程,例如复杂的图形渲染、用户交互、甚至是桌面通知等。然而,Web应用在跨平台和用户体验方面仍存在痛点。一方面,依赖于浏览器的Web应用在没有浏览器的环境下无法运行;另一方面,Web应用的性能也往往受限于浏览器的种种限制。

nwutils的Web2Executable项目正是为了解决这些问题。它使用NW.js(Node.js + Chromium)将现有的Web应用打包成为跨平台的原生应用。这样一来,用户可以享受桌面应用的性能和体验,同时还能跨平台部署和分发,极大地提升了应用的用户体验和可部署性。

核心技术揭秘

Web2Executable的核心技术在于利用NW.js提供的Node.js运行环境和Chromium的渲染能力,将Web应用的前端和后端进行了融合。通过NW.js,开发者可以使用Node.js的所有模块来增强Web应用的功能,比如文件系统操作、网络请求等。

下面是一个简单的架构示意图,展示了如何利用NW.js将一个Web应用转化为一个本地原生应用:

graph TD A[用户通过浏览器访问Web应用] --> B[收集前端资源] B --> C[打包为NW.js项目] C --> D{"选择打包平台"} D -->|"Windows"| E[生成Windows可执行文件] D -->|"macOS"| F[生成macOS安装包] D -->|"Linux"| G[生成Linux可执行文件] E --> H[用户下载并运行Windows可执行文件] F --> I[用户下载并运行macOS安装包] G --> J[用户下载并运行Linux可执行文件]

在打包过程中,nwutils/Web2Executable项目会先收集Web应用前端的所有资源,例如HTML、CSS、JavaScript文件等,然后将这些资源打包成一个NW.js项目结构。用户可以根据目标平台,选择生成Windows的.exe文件、macOS的.app安装包或Linux的可执行文件。这主要依赖于NW.js提供的打包工具,nw-gyp 和 nw-build。

功能亮点与差异

与其它类似的解决方案(如Electron)相比,nwutils/Web2Executable的优点在于它更加轻量级,更易于定制和优化。NW.js本身代码量较少,同时依赖的Node.js模块和Chromium版本可以自由选择,这给了开发者更多的灵活性。此外,NW.js项目本身提供了丰富的插件和扩展,用于增强性能和功能。

竞品中,Electron由于其用户群体庞大、应用广泛,因此有更为成熟和全面的周边生态系统。但值得注意的是,Electron的体积往往较大,并且可能带来更多的内存占用。相比之下,Web2Executable的亲业务性体现在其“轻量化”的设计上,更加适合资源占用敏感的应用场景。

应用场景与落地建议

在生产环境中使用Web2Executable时,需要注意以下几个方面:

  1. 应用体积控制:由于采用了NW.js,应用默认使用Node.js和Chromium,可能导致初始应用体积较大。因此,可以通过优化前端代码、裁剪不必要的模块以及设置打包参数来减小体积;
  2. 资源管理与安全性:在打包过程中,确保所有敏感信息和资源都得到妥善处理,遵循最小权限原则;
  3. 跨平台兼容性:虽然NW.js提供了跨平台的能力,但仍需要考虑不同系统上的用户体验差异,确保在各个平台上都能正常运行。

该工具特别适合那些希望通过现有Web应用快速生成原生桌面应用的开发者和小团队,适用于工具类应用、小量级桌面工具箱、以及简单但需要原生体验的小型项目。

综合评价

nwutils/Web2Executable是一个轻量级、灵活且高效的解决方案,它能够快速实现代浏览器Web应用到跨平台原生应用的过渡。其优点在于其简洁的实现和较小的资源占用,非常适合小型团队或个人开发者。不足之处在于它也可能带来一定的性能问题,特别是对于依赖大量Node.js模块或高复杂度前端应用的情况。

总的来说,这项技术是一个值得尝试的工具,尤其在追求快速开发和跨平台兼容性的场景中,能够提高开发效率并降低部署成本。

关于

GitHub 原始描述(英文)

Uses NW.js to generate "native" apps for already existing web apps.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1284
价值分
628
活跃状态
活跃

语言占比

Batchfile
NSIS
Python
Shell

Release

README

This repository is in maintainance mode. Bug fixes will be provided on a best effort basis. If you use this project, please consider contributing back.

Web2Executable

Github Releases (by Release)

Releases (Downloads) (new!)

Github All Releases

What is it?

Web2Executable is a friendly command line and GUI application that can transform your Nodejs (or any other JS/HTML) app into an executable (and libraries) that can run in a contained, desktop-like style. It can export to Mac OS X, Windows and Linux all from one platform, so no need to go out and buy expensive hardware.

It’s powered by the very awesome project NWJS and PySide, is open source, and is just dang awesome and easy to use.

If you have an idea for a feature, please create a new issue with a format like this: “Feature - My Awesome New Feature”, along with a good description of what you’d like the feature to do.

On the other hand, if you have any annoyances with the application and want to contribute to making it better for everyone, please file an issue with “Annoyance:” as the first part of the title. Sometimes it’s hard to know what is annoying for people and input is much appreciated :)

What About Electron?

If you want to export using Electron instead of NW.js, try Electrify, my other app based on Web2Executable.

Who’s Using It?

Lots of people! There are currently thousands of downloads and several articles written about using Web2Executable.

Some articles include:

Getting a Phaser Game on Steam

Packt Publishing NW.js Essentials Tutorial and Ebook

A Russian NW.js Tutoral

Marv’s Blog

Shotten.com Node-webkit for Poets

If you have a project you’d like to see listed here that was successfully built using Web2Executable or you have written an article that mentions it, feel free to send me an email with a link and I’d be super stoked to paste it here :)

Features

  • Cross platform to Mac, Windows, Linux
  • Working media out of the box (sound and video)
  • Easy to use and straightforward
  • Streamlined workflow from project -> working standalone exe
  • Same performance as Google Chrome
  • Works with Phaser; should work with other HTML5 game libraries
  • Export web applications to all platforms from your current OS
  • Ability to specify a node-webkit version to download
  • Automatic insertion of icon files into Windows exe’s or Mac Apps by filling out the icon fields as necessary
  • A command line utility with functionality equivalent to the GUI. Useful for automated builds.
  • Compression of executables with upx

Planned New Features

  • The ability to add external files to the project
  • Minifying JS and HTML

Getting Started

Using Prebuilt Binaries

When using the prebuilt binaries for Windows, Mac, or Ubuntu, there are NO dependencies or extra applications needed. Simply download Web2Exe for the platform of your choice, extract, and double click the app/exe/binary to start. This applies to both the command-line version and the GUI version.

NOTE!: Some people report needing the Microsoft Visual C++ 2008/2010 SP1 and regular Redistributable package. I don’t have a machine to test this, but just know that you might need the package if the application won’t open or spits out the following error:

Error: The application has failed to start because the side by side configuration is incorrect please see the application event log or use the command line sxstrace.exe tool for more detail.

Building from Source

Requires the PySide library and Python 3.4.3 or higher. If you want to replace the icon in the Windows Exe’s, this will do it automatically with the latest code if you have PIL or Pillow installed.

Command line interface

Dependencies: configobj (install with pip) and Pillow if you want icon replacement (not necessary)

Run the command_line.py with the --help option to see a list of export options. Optionally, if you don’t want to install python, there are builds for Mac and Windows in the command_line_builds folder of this repository.

Example usage (if using the prebuilt binary, replace python3.4 command_line.py with the exe name):

python3.4 command_line.py /var/www/html/CargoBlaster/ --main html/index.html --export-to linux-x64 windows mac --width 900 --height 700 --nw-version 0.10.5

GUI

Install dependencies:

pip install -r requirements.txt

Initiate submodules:

git submodule update --init --recursive

Run with:

python3.4 main.py

General Instructions for exporting:

  1. Choose a project folder with at least one html or php file. The name of the export application will be autogenerated from the folder that you choose, so change it if you so desire.
  2. Modify the options as needed.
  3. Choose at least one export platform and then the Export button should be enabled (as long as the field names marked with a star are filled out and all files in the fields exist).
  4. Click the export button and once it’s done, click the “Open Export Folder” button to go to the folder where your exported project will be.

Issues?

If you have an issue, please check the FAQ before filing an issue to see if it helps.

FAQ

Additional Info

Changelog

Screenshots

License

The MIT License (MIT)

Copyright © 2015 SimplyPixelated

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

评论

暂无评论