Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the compilation so heavy? 🎸 #77

Open
JTorresConsulta opened this issue Jan 10, 2024 · 3 comments
Open

Why is the compilation so heavy? 🎸 #77

JTorresConsulta opened this issue Jan 10, 2024 · 3 comments

Comments

@JTorresConsulta
Copy link

On Windows.:

Compiling with "nwjs-packager" result a 504mb directory for a "hellow world" project with only a index.html 1kb file.
Also the .exe takes a long time to open.

Why?

Compiling with "nwjs-builder-phoenix" result a 146mb for the same project and the .exe open fast. Unfortunately the index.html is visible in the compilation directory ...

Any idea how to reduce the weight and slow opening ? Thanks

@JTorresConsulta JTorresConsulta changed the title Why is the compilation so heavy ? Why is the compilation so heavy? 🎸 Jan 10, 2024
@TheJaredWilcurt
Copy link
Member

TheJaredWilcurt commented Jan 10, 2024

Ways to package your NW.js app.

  • Put your package.json and related source files next to nw.exe
  • Put them in a package.nw folder next to your nw.exe
  • Put them in the root of a Zip archive, then:
    • drag/drop it on to nw.exe
    • run nw.exe with an command line argument pointing to the zip
    • Merge the zip file and exe together using copy /b nw.exe+package.zip app.exe then run app.exe

If you use zip archives in ANY WAY AT ALL, every time you open your app, NW.js will need to unzip all the files to a temp folder (like C:\Temp\something). Then it will run the app pointing to the temp folder location. This means every startup incurs an additional wait time to unzip the files before the app can be ran. It is because of this that we generally say that using Zip files with NW.js in any capacity is an anti-pattern.

You should ask yourself why you care if the index.html file is visible when distributing your app. Anyone with very basic NW.js knowledge would be able to locate the zip file and unzip your files. Even if you combine the zip with nw.exe to create app.exe you can still rename it to app.zip to access the files.

If you do not want your code to be readable in plain text, either use source protection (see NW.js docs) or store the files on a remote server.


My guess at what is happening:

  1. You have something big in your dependencies (like nw for example) that should be moved to your devDependencies so it is not included in the build.
  2. You are using a setting to allow for zips and dealing with the problems that come with that. There are no benefits to using zips. Do not use zips.

@JTorresConsulta
Copy link
Author

JTorresConsulta commented Jan 10, 2024

@TheJaredWilcurt Hi!

  1. My project works with global devDependencies (nw and builders)
  2. I am not using zips

No problem with my source files are visible, the problem is my app will be in a USB memory stick and the .html init file icon has the system navigator icon and curious people can simply open it and then see the entire page distorted.
I would like to be able to make the package as simple and compressed as possible in the eyes of the user. It's not a question of safety, it's a question of aesthetics :)

Maybe there are a way to load into app.exe the "main" as other file that chromium recognizes but not chrome , edge, firefox ..?

@TheJaredWilcurt
Copy link
Member

TheJaredWilcurt commented Jan 13, 2024

Put this in your HTML file. Then if people open it, they are redirected to the correct place and don't see anything.

<!DOCTYPE html>
<html>
  <head>
    <script>
      if (!window.nw) {
        document.body.innerHTML = '<h1>To open this app, run AppName.exe</h1>';
      }
    </script>

You can create an autorun.inf file and put it at the root of the Flash drive:

[autorun]
open=AppName.exe
icon=icon.ico
label=AppName

This only works on Windows, but it will show the correct icon and label when you plug it in, and depending on the users settings it will either auto launch your EXE, pop open a window for the user to decide if they want to launch the EXE, or do nothing. Usually the second one.


You can put all your files in a package.nw folder and place them next to your nw.exe. Then when you run nw.exe it will look for your manifest at ./package.nw/package.json and when it finds it, launch like normal. So you can sort of hide away your files in there. People can still go snooping around, but that's the case with basically any desktop app. You can package most of your JS into a .bin file if you really need to keep that code secret. But it's extra effort to create for each platform.


You can store all your app files in a hidden folder on the drive and just create a desktop shortcut to point to the .exe in the folder. Then for most users all they will see when they plug in the drive is the auto-launcher and in the drive a single icon for your app to click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants