We are using node-red to create electron-based windows application that we ship to our clients as a .exe installer. Currently the installer unpacks our files, including the node_modules. We can't install node_modules during installation, since many of our clients are using the application in an isolated environment.
What we want to achieve now is pre-bundle the application's code(including our own nodes, developed for internal purposes) with a tool like webpack or parcel. During my first tries I have encountered a number of issues, which I am tackling one by one. Regarding my effort, I have two questions:
Has anyone ever achieved bundling of the application, including own nodes?
Is it possible to "import" local nodes and register manually, instead of using npm_module link method? If I can import them, the bundler will pick-up the node's code easier. Otherwise I may have to do some hack like copy/paste the whole nodes directory in the build folder.
I think you can do an npm pack can't you? That will bundle all of the dependencies into a deployment archive.
You can "install" local nodes using a filing system reference. The trick for Electron will be making sure that relative URL's are used that will work on both the dev machine as well as the target machines.
Also, remember that npm is hierarchical. When I install Node-RED, I install locally not globally and I use a userDir that is a sub-folder of the Node-RED folder. That means that I can install npm packages at the Node-RED folder level which prevents them being managed by the palette manager but they still show up. Probably useful for your case.
As far as I understand npm-pack will pack a tarball, but the client still has to unpack the it in order to use it? This is not ideal in our case, best case scenario we are aiming at is bundling all the code we use into a few files that are minified.
About the userDir -> I have tried putting my nodes in the .node-red global folder, where the flows and configs exist, but that didn't work. I also tried including them as sub-directory to the node-red code directory(where node-red is locally installed). But without having the link in package-json, this doesn't work either. Am I missing something? How to use the userDir? I have found a configuration variable called coreNodesDir, which if I replace it with the nodes directory, they get picked up, but the issue is that the variable is supposed to be used for core nodes, not customly developed ones, and my core nodes get overwritten. Is there such configuration for a local custom nodes folder, that will just add the nodes to the pallete, without overwriting the core ones?
Not sure that makes sense. An installer would have no issues unpacking an archive as part of the install, this is a very common scenario.
Also the total number of files in the installed code for Node-RED is not "few" but "SIGNIFICANT" which is a common Node.js issue. Here is my dev install (both Node-RED and userDir with a few installed nodes (some are local installs and so their files don't even appear in this summary):
Still, after tree-shaking and minification, bundle-size and file number should be able to drop dramatically. Basically what I am aiming is tree-shake the code we use from node_modules and minify it before shipping to customers. Is that use case understandable?
What I meant is that they can't install the node_modules themselves, so we have to ship it somehow. But shipping the whole node_modules folder comes with potential issues, hence the reason behind tree-shaking and minification.
Hey guys, thank you very much for spending time to reply, your replies have been helpful to clear the picture. For this moment the task has been freezed as we were not able to find a suitable solution for our needs. I will provide an updated if that changes.