Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the recommended method to add nativescript plugin #17

Closed
mahmoudajawad opened this issue May 2, 2021 · 8 comments
Closed

What is the recommended method to add nativescript plugin #17

mahmoudajawad opened this issue May 2, 2021 · 8 comments

Comments

@mahmoudajawad
Copy link
Contributor

When an NS app is created using this Nx plugin, it creates app-specific packages.json file inside the app folder. Assuming I'm going to install nativescript plugins to be used in the app using npm, which packages.json file should be modified for that?

On another instance, how can I use NS CLI to add plugins to apps in Nx workspace? Where the CLI would add the package, and is it the best practice for both NS and Nx?

@NathanWalker
Copy link
Contributor

NathanWalker commented May 6, 2021

@mahmoudajawad This is a topic that comes up often. Generally Nx approach prefers to manage all dependencies at the root package.json. This typically works well and usually you could even share those root level package dependencies via file ref's to various app packages. However webpack5 does not currently like file referenced dependencies (those like "file: ../../etc.."). We've been exploring various configurations with webpack5 which may play well still with file ref'd deps as although it may look ugly it's quite useful in practice. We're also exploring the ability to not even have to define package dep's of {N} apps in their own package by utilize webpack to pull naturally from even the root package.json.

Currently you will want to manage your dependencies at the root for the workspace in general and can configured package dep's in the {N} app as well. This will likely shift in the coming weeks as webpack5 is evolving fast.

@mahmoudajawad
Copy link
Contributor Author

That's verbose and I appreciate. Also, what about using NS CLI to add plugin? Do I use ns add plugin X as usual or do I do something different?

@NathanWalker
Copy link
Contributor

NathanWalker commented May 12, 2021

@mahmoudajawad You can cd apps/nativescript-yourapp and use ns add plugin X as usual or you can install a plugin in root and share it up and install with npm directly into the app. Flexibility in that regard for whichever fits your case there.

@mahmoudajawad
Copy link
Contributor Author

I see. That's where I failed as I didn't try to run the command from the app folder, but root.

Would you welcome a quick PR to point this out in README? I do think adding it is worth it as huge part of NativeScript is its amazing eco-system of plug-ins and libs.

@mahmoudajawad
Copy link
Contributor Author

@NathanaelA, what do you think of this:
https://github.com/mahmoudajawad/nx/commit/5468e2cee76b572bef33e036ed3a9b816c40d84d

Also, I added some notes about versions as one of the biggest challenges I usually come across with any nativescript written-material is the inability to figure out the correct version-pool for the different parts of the structure.

@mahmoudajawad
Copy link
Contributor Author

An update to using both the approaches:
It seems that plugins that require pods (iOS) don't seem to work if installed at root-level, but fine on app-level. For instance, I tried installing both:

@nativescript/background-http
nativescript-websockets

at root-level, which rendered an error with nativescript-websockets. Afterwards, I installed it at app-level and it worked fine. I just want to be clear that I didn't clear nativescript app folder (npx nx run nativescript-<app-name>:clear) before re-running the app.

@NathanWalker
Copy link
Contributor

@NathanaelA, what do you think of this:
mahmoudajawad@5468e2c

Also, I added some notes about versions as one of the biggest challenges I usually come across with any nativescript written-material is the inability to figure out the correct version-pool for the different parts of the structure.

Thank you - left couple quick comments there and with those changes a PR would be much appreciated.

An update to using both the approaches:
It seems that plugins that require pods (iOS) don't seem to work if installed at root-level, but fine on app-level. For instance, I tried installing both:

@nativescript/background-http
nativescript-websockets

at root-level, which rendered an error with nativescript-websockets. Afterwards, I installed it at app-level and it worked fine. I just want to be clear that I didn't clear nativescript app folder (npx nx run nativescript-<app-name>:clear) before re-running the app.

This is something we've been investigating as well. We believe it's related to npm 7 or webpack5 or cli (or all the above). Anticipate having that triaged this month because that should work the same whether coming from root package or app's package but you are correct right now that if a plugin contains platforms folder with native includes, the plugin must be added to app package.json at moment.

@mahmoudajawad
Copy link
Contributor Author

Closed by #22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants