eclipsesource / J2V8

Java Bindings for V8
2.54k stars 356 forks source link

File structure & build approach for larger NodeJS projects #300

Open roomofdoom opened 7 years ago

roomofdoom commented 7 years ago

Hi,

What would be the best way to go about running larger projects with J2V8? I have a project with a ±50 internal modules and same amount of dependencies. All the documents point to creating a temp file and then executing that file. I'm testing on J2V8 ARM arch, using the docker build on Mac. Simple scripts are working beautifully.

I've tried 2 approaches so far for a larger project and would like to find out which approach to focus on to get my application running using J2V8.

1st approach - bundling into 1 file

I have tried using Webpack to bundle the whole project into one file and then package the bundle file as an Asset. Issue so far is getting the bundled file to execute even on normal Node side so it's more a Webpack issue, but I'm wondering if it's worth going through the effort if there is another solution.

2nd approach - packaging entire project as APK Assets

I included the entire NodeJS project as an Assets directory in the APK and use only the application entry script to start the node instance using J2V8. The issue here is finding all the required modules from the execution path in Android (using the temp file), I couldn't yet set up my include path correctly.

If the 2nd approach has a chance of working I would prefer it, but any solution will help!

What would be the best approach for the application to work in this case?

Regards,

aschrijver commented 7 years ago

I am new to J2V8, investigating node on android (specifically interested in calling node api's from a react-native app, circumventing the shimming PITA) and just coming from https://github.com/mafintosh/node-on-android

But I would definitely go for the 1st approach. If I understand correctly the 2nd approach transfers the node_modules folder as well? That is really costly in terms of storage.

Just use webpack with babel or other bundling solutions, start from a good boilerplate, and go from there.

irbull commented 7 years ago

While I developed J2V8, I don't use the Node capabilities, so I can't comment on best practices for this. However, I think this is a very valuable discussion to have, so let's leave this issue open and hopefully those with some experience can comment here.

aschrijver commented 7 years ago

@roomofdoom @irbull I have created an in-depth overview of 3 oss approaches to android + nodejs apps (and node compilation info). I think of the three J2V8 holds pretty good cards. See:

aschrijver commented 7 years ago

With regards to point no. 1 on bundling node apps I found these two interesting projects:

aschrijver commented 7 years ago

Note: This topic should be part of the Future direction and vision of the J2V8 project discussion.