bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
323 stars 85 forks source link

About current features and abilities #12

Closed LouisSung closed 4 years ago

LouisSung commented 4 years ago

Hi,

Actually, I'm new to NestJS, Nx, and Electron and not sure if these problems are solvable _(;3 Thank you for building this project and reading these questions : )

bennymeg commented 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.

LouisSung commented 4 years ago

:o Thanks for your quick reply!!

  1. OK~
    • I use the Angular-Nest archit. provided by Nx, which create app and api as projects separately
  2. I’m not sure the difference between make and package :p
    • I run both and at least package one works
      • The binary file generated by package can only be executed via terminal
      • While the make one generate a clickable execution but with blank window. I’ll give it a try a few hours later :)
  3. :o that’s cool! I’m using WebStorm, that’s why I didn’t get the command hints support. I’ll try it too.
  4. I’m using the latest @9.0.0-beta1, but not knowing the difference between the make and package

Thanks a lot!!

bennymeg commented 4 years ago

I hope that answer you questions, Benny.

LouisSung commented 4 years ago
bennymeg commented 4 years ago
  • 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.

LouisSung commented 4 years ago

bennymeg commented 4 years ago
  • 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.

  • Another problem I met was that make didn't have as many configurable options as packaged, is that normal because make is still under development?

    • For example, there are no options like ignoreSourceMap, prune, etc. at least in the JSON schema (make vs package)

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 in maker.options.json and nothing happens, while the packager.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.

bennymeg commented 4 years ago

I will close this issue for now, feel free to continue the conversation. Good look.

LouisSung commented 4 years ago

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

  1. (Critical) Is there any ways I can force electron-builder to bundle specify package into the exectuable?

    • I got Error: Cannot find module 'tslib' when I try to use async/await function in Electron
    • I try to solved this problem (e.g., install electron@8.2.0, use two-package-structure, and set externalDependencies) but just not work
    • I wonder if there's ways to force electron put tslib into executable (is npmArgs responsible for this?)
  2. 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.


bennymeg commented 4 years ago

Hi, good progress.

  1. You can try moving tslib to the dependencies block.
  2. You can use socket.io websocket in conjunction with nestjs

What does the project structure look like?

LouisSung commented 4 years ago

Hi,

Here's my code @https://github.com/LouisSung/tmp-nx



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).