NodeWebkit - deploy the application

2019-09-04 04:22发布

问题:

I have one code base for both Web and NodeWebkit (NW) application. I use the following stack: - React - Hapi - Sequelize - Windows environment

Web version of the application uses MySQL, while NW uses Sqlite. It all works fine. I have config file that compiles application for what I need (web or NW).

The problem that I face now is how to deploy the NW application. Idea is to provide NW applicaiton to a client, where he will open it clicking the icon.

Since I use the Node for the NW version, and the application uses many modules which are stored in node_modules, I face a challenge how to pack it all up.

My idea is to make an Windows installer. User will click it and the installer will extract all files to the destination. And also make an icon on the user desktop to run it.

Problem is with the Windows file name limitation. Inside the node_modules, there are many subdirectories that simply violate the Windows limitation. I cant even copy the node_modules folder. I cant even delete it. Well sure I can copy it If I zip it... or remove manually long folders.

I have not yet started working on the installer, but I am thinking I will hit the wall with this approach.

Does anyone have an idea how to make this deployment? How can I integrate NPM3 in NW?

My plan now is to make Windows installer. That windows installer will install normally application files. The node_modules will be zipped previously and placed inside the installer. Installer will then simply unzip it to the destionation folder.

I will post my progress here.

Some update here. Main issue here was the depth of the node_modules. I have many modules in node_modules, and after some thinking I figured out there is a simple rule there. Some modules are server side modules, while other ones are used by react. And since Webpack already creates a huge files in which all of the modules are already included, I simply do not need them at all.

So I have removed all front end side modules(babel modules, react-*), and left only server side (Hapi, sequelize...). Miracle happened, application run and was much faster at the startup.

I am going to use Inno setup to make a manifest file, and it should be good to go.

I am still not out of the danger zone, as developer might need a server side module, which has huge depth. But I will think about that if it happens.

More to follow...

回答1:

actually in nodejs you can do the following:

1-Create another folder inside your project folder for example "server_modules"

2-In the created folder create another package.json file and install any modules needed for server out there

3-All these modules will be accessible as normal node_modules using require('module_name') and you can delete "server_modules" folder when you package your desktop version if you don't need it

Note: this approach used by some developers to achive micro services in nodejs but it is useful in your case