You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What is the recommended method to add nativescript plugin #17
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?
@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 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.
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.
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.
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:
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.
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:
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.
Activity
NathanWalker commentedon 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 commentedon May 6, 2021
That's verbose and I appreciate. Also, what about using NS CLI to add plugin? Do I use
ns add plugin Xas usual or do I do something different?NathanWalker commentedon May 12, 2021
@mahmoudajawad You can
cd apps/nativescript-yourappand usens add plugin Xas 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 commentedon May 12, 2021
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 commentedon May 14, 2021
@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 commentedon May 15, 2021
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:
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 commentedon May 15, 2021
Thank you - left couple quick comments there and with those changes a PR would be much appreciated.
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
platformsfolder with native includes, the plugin must be added to app package.json at moment.mahmoudajawad commentedon May 16, 2021
Closed by #22.