Skip to content

Commit 064870a

Browse files
committed
packages
1 parent 947aeac commit 064870a

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

development-workflow.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,106 @@ To integrate the NativeScript unit test runner into a continuous integration pro
995995
996996
## Using packages
997997
998+
### Plugins
999+
1000+
NativeScript plugins are npm packages with some added native functionality. Therefore, finding, installing, and removing NativeScript plugins works a lot like working with npm packages you might use in your Node.js or front-end web development.
1001+
1002+
#### Finding plugins
1003+
1004+
The NativeScript team maintains an [official marketplace](https://market.nativescript.org/), which displays a filtered list of NativeScript-related plugins from npm. All plugins listed in the marketplace are accompanied by a metadata describing their quality. A search for “accelerometer” on the plugins marketplace will point you at the plugin you need.
1005+
1006+
Alternatively, since NativeScript plugins are npm packages, you can find NativeScript plugins on [npm’s site](https://www.npmjs.com/) by searching for “nativescript-plugin-name”. For example, a search of “nativescript accelerometer” would point you right at the [NativeScript accelerometer plugin](https://www.npmjs.com/package/nativescript-accelerometer).
1007+
1008+
If you can't find a plugin, try asking for help on [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript). The NativeScript team and community may be able to help find what you’re looking for.
1009+
1010+
Also, make sure to look through the [NativeScript core modules](https://docs.nativescript.org/core-concepts/modules), which ship as a dependency of every NativeScript app. There’s a chance that the functionality you need is built in. If you’re still not finding what you need, you can request the plugin as an idea on the [NativeScript community forum](https://discourse.nativescript.org/c/plugins), or you can take a stab at [building the plugin yourself](/plugins/building-plugins/).
1011+
1012+
#### Installing Plugins
1013+
1014+
Once you’ve found the plugin you need, install the plugin into your app using the `tns plugin add` command.
1015+
1016+
```node
1017+
ns plugin add <plugin-name>
1018+
```
1019+
1020+
For example, the following command installs the [NativeScript camera plugin](https://market.nativescript.org/plugins/@nativescript/camera).
1021+
1022+
```node
1023+
ns plugin add @nativescript/camera
1024+
```
1025+
1026+
If you prefer, you could use the NPM command `npm install` instead of the NativeScript CLI command `plugin add`.
1027+
1028+
```node
1029+
npm i @nativescript/camera --save
1030+
```
1031+
1032+
The installation of a NativeScript plugin mimics the installation of an npm package. The NativeScript CLI downloads the plugin from npm and adds the plugin to the `node_modules` folder in the root of your project. During this process, the NativeScript CLI adds the plugin to your project’s root `package.json` file and also resolves the plugin’s dependencies (if any).
1033+
1034+
#### Installing Plugins as Developer Dependencies
1035+
1036+
As shown above the command **ns plugin add PLUGIN_NAME** is actually doing **npm i PLUGIN_NAME --save** behind the scenes. If you need to install a **developer dependency** in your project (e.g., like **@nativescript/types** or **@nativescript/webpack**) then you will need to explicitly save it as a **devDependency**. To achieve that, use the **npm install** command with **--save-dev** flag. For example:
1037+
1038+
```shell
1039+
npm i @nativescript/types --save-dev
1040+
```
1041+
1042+
::: tip Note
1043+
The difference between dependencies and developer dependencies is that **dependencies** are required to run, while **devDependencies** are needed only during development. Example for dependency is the **@nativescript/camera** plugin which is required runtime so you could use the hardware camera. On the other hand, the **@nativescript/types** is a developer dependency required only for intelliSense during the development process. The `devDependencies` should not be installed as `dependencies` to avoid large output build files (large application size). Example `package.json` file using both `dependencies` and `devDependencies` can be found [here](https://github.com/NativeScript/nativescript-sdk-examples-js/blob/master/package.json#L31-L44).
1044+
:::
1045+
1046+
#### Importing and Using Plugins
1047+
1048+
Once the plugin you need is installed, you can start using it in your project. Note that each plugin might have its configuration that needs to be satisfied so always check carefully the plugin's documentation and the README file. The below code snippet demonstrated the basic usage of **@nativescript/camera** plugin.
1049+
1050+
```javascript
1051+
import { requestPermissions } from '@nativescript/camera'
1052+
requestPermissions()
1053+
```
1054+
1055+
```typescript
1056+
import { requestPermissions } from '@nativescript/camera'
1057+
requestPermissions()
1058+
```
1059+
1060+
#### Removing Plugins
1061+
1062+
To remove a NativeScript plugin from your project, run the following command from your command line.
1063+
1064+
```node
1065+
ns plugin remove <plugin-name>
1066+
```
1067+
1068+
For example, the following command removes the NativeScript camera plugin.
1069+
1070+
```node
1071+
ns plugin remove @nativescript/camera
1072+
```
1073+
1074+
As with installation, the removal of a NativeScript plugin mimics the removal of an npm package.
1075+
1076+
The NativeScript CLI removes any plugin files from your app’s `node_modules` folder in the root of your project. The CLI also removes any of the plugin’s dependencies and also removes the plugin from your project’s root `package.json` file.
1077+
1078+
### Package Managers
1079+
1080+
A package manager is a piece of software that lets you manage the external code, written by you or someone else, that your project needs to work correctly. By default, NativeScript CLI uses Node Package Manager (`npm`) for managing the dependencies of the application. When new application is created, CLI automatically calls `npm install` to install all of its dependencies.
1081+
1082+
#### Supported package managers
1083+
1084+
NativeScript CLI allows you to configure the package manager used when working with dependencies. When you change the defaultly used `npm` package manager, CLI will use the newly set package manager for all operations it executes related to project dependencies, for example, project creation, managing dependencies, etc.
1085+
1086+
NativeScript CLI supports three package managers:
1087+
1088+
- `npm` - this is the default option
1089+
- `yarn` - you can set it by calling `ns package-manager set yarn`. More information about `yarn` is available [here](https://yarnpkg.com/)
1090+
- `pnpm` - from version 6.4, you can use `pnpm` to manage the dependencies of your application. You can use `pnpm` by calling `tns package-manager set pnpm`. NOTE: You will have to use `--shamefully-hoist` flag if you call `pnpm` on your own. CLI passes this flag when installing dependencies with `pnpm` and probably your application will not work if you omit it. More information about `pnpm` is available [here](https://pnpm.js.org/).
1091+
1092+
In case you want to check what is the currently used package manager, you can use:
1093+
1094+
```
1095+
$ ns package-manager get
1096+
```
1097+
9981098
## Updating
9991099
10001100
To upgrade a NativeScript application you need to upgrade several things: NativeScript CLI Tooling, the iOS and Android runtimes and the `@nativescript/core` module. In the steps below you will see how to do this.

0 commit comments

Comments
 (0)