Closed LouisSung closed 4 years ago
Hi, Louis, Thank you for your questions, I will try to answer them below:
i) I am not sure why you have 3 project there, is the api not part of the electron app (i.e. nestJS app)? if so, that is correct. keep in mind that build you project only required when you ready to package you project, otherwise, serving you project is the way to go (more info below).
ii) Correct, in development you serve you app locally (frontend and backend), it allows you (along other things) continues builds while you update you code. You can use package
/ make
once you ready to test your app in production.
iii) Yes, It is implemented, you just have to pass --obfuscate to you command. I recommend using nx-console
for vs-code
, it will show you all the options in a nice graphical ui (be aware, currently they have a bug when invoking a production command).
iv) Yes! If you will updatenx-electron
to the latest beta you will find a make
command. It will allow you package your project into a single executable (along other cool features).
Best, Benny.
:o Thanks for your quick reply!!
app
and api
as projects separatelymake
and package
:p
package
one works
package
can only be executed via terminalmake
one generate a clickable execution but with blank window. I’ll give it a try a few hours later :)@9.0.0-beta1
, but not knowing the difference between the make
and package
proxy
so that Angular can route the requests to API server.port 4200
and NestJS uses port 3000
(3333 by Nx default though)Thanks a lot!!
I hope that answer you questions, Benny.
Nest is an backend for the application itself, it should not be packaged inside the electron app
- Is that still possible to package application api in Electron and run it so that user can run everything totally in the localhost using single executable? Or user must deploy another API server manually without integrated into Electron?
- Did I misunderstand what backend mean in the doc? (
Packaging: Packages your frontend and backend webpack bundles
)- I used to think both Angular and NestJS can be built and packaged into an Electron app, while Angular part is served as static files with rendering (like Nginx+Chrome) and NestJS part is served as normal Node.js application
- Is that still possible to package application api in Electron and run it so that user can run everything totally in the localhost using single executable? Or user must deploy another API server manually without integrated into Electron?
Well, I assume you can build you api , copy the compiled output into your main process app (or by adding the api dist folder to the maker config file), and initialize the server when the app is initialized.
- Did I misunderstand what backend mean in the doc? (
Packaging: Packages your frontend and backend webpack bundles
)
In the docs, when I say 'backend' I mean the main process of electron. I think electron application are unique at that matter.
- I used to think both Angular and NestJS can be built and packaged into an Electron app, while Angular part is served as static files with rendering (like Nginx+Chrome) and NestJS part is served as normal Node.js application
I think that is possible, but you will have to experiment it as i explained in the first bullet, I didn't though that is a needed feature. I would be happy to learn more about it if you have some material about that topic.
Actually I find out the explanation for backend
over here a moment ago :p
Although there are lots of security issues to solve and prevent, it might still be useful if the API server can be integrated into Electron executable (at least for our purpose)
make
didn't have as many configurable options as packaged
, is that normal because make is still under development?
ignoreSourceMap
, prune
, etc. at least in the JSON schema (make vs package)Property 'xxx' is not allowed
if the "$schema": "../../../../../node_modules/nx-electron/src/validation/maker.schema.json"
is set."asar": true
in maker.options.json
and nothing happens, while the packager.options.json
work fine. Is that a bug?
- I'll try to use the approach mentioned in first post and give some examples or tutorials if succeed
Great, keep me posted if you succeed.
By default, make ignore source map files and prune you node modules, it also handles rebuilding native modules for electron.
- WebStorm warn
Property 'xxx' is not allowed
if the"$schema": "../../../../../node_modules/nx-electron/src/validation/maker.schema.json"
is set.
I have configured a schema that validates the options file so only valid options will be used.
- Also, I set
"asar": true
inmaker.options.json
and nothing happens, while thepackager.options.json
work fine. Is that a bug?
All the setting that you see in nx-console
override the setting you set in the config file. if you use the GUI you can either check asar, if not you can use the --asar option and let me know.
I will close this issue for now, feel free to continue the conversation. Good look.
Hi, I'm here to update status.
It's able to fork a NodeJS process and use it to run NestJS as API server as of now. However, there are 2 problems required to solve
(Critical) Is there any ways I can force electron-builder to bundle specify package into the exectuable?
Error: Cannot find module 'tslib'
when I try to use async/await
function in Electrontslib
into executable (is npmArgs
responsible for this?)Using IPC (e.g., Unix Domain Socket) is much safer than bind to localhost port. I'm not sure if NestJS can bind to socket rather than port and have to give it a try.
initMainWindow
, so that angular can send request and get response.
Hi, good progress.
What does the project structure look like?
Hi,
Here's my code @https://github.com/LouisSung/tmp-nx
Steps (on Ubuntu 18.04)
yarn install
> yarn ls:build:all
> yarn ls:prod:standalone
should workyarn ls:prod:exe
should failed (will explain later)Some critical implementation
extraResources
(it won't be packed into asar... and I cannot find out how)async function
, and the yarn ls:prod:standalone
will failedtslib
in package.json
and apps/standalone/package.json
tslib
not found error. I think they are different but both required tslib
??
BTW, I'm facing another issue is that I can get random port and apply it to NestJS easily, but haven't found any way set up Angular. So I just hard code it now.
I'd like to!! But I think I haven't done it right yet QQ
- I think you should try adding nestjs to you electron project (combining you electron backend and your api backend).
Angular
& Nest + Electron
? :o
Angular
, NestJS
and Angular+NestJS
)Angular+NestJS > Electron
)
Hi,
nx build app --prod && nx build api --prod && nx build standalone--prod && nx run standalone:package
to build a standalone executable. (ps: I usenx run standalone:make
now)./dist/packages/standalone-linux-x64/standalone
to run the app rather thannx serve standalone
(ps:./dist/executables/linux-unpacked/app
)nx serve
one seems like under the dev mode rather than the prod mode?ng serve app
andng serve api
(as issue #10 discussed)nx build app --prod
manually so that Electron can get these pre-processed files?nestjs/nest#910
) but seems there's no official support after thenjlongster/electron-with-server-example
, but I haven't gave it a try yet