Everyday app development
After you created a project for a new app or got the sources of an existing app, you can start developing your app.
Install dependencies
Install the required Node.js dependencies with the npm ci command.
You need to do this at the beginning of the development process. Later, this is required only if the dependencies change.
Compiling
You can use the following commands for compiling your application:
-
npm run watch(recommended) - This command compiles and packs all your code intodist/bundle.js. It also continuously checks the types. It then waits and watches your code. Whenever you save source files, it creates a newdist/bundle.js. You can stop it at any time with Ctrl-C. -
npm run build:dev- If you just want to compile and pack the code only once. -
npm run build:prod- If you want to create adist/bundle.jspackage that is optimized for production use (for example, the bundle is minified).
Running
Complete the following steps to run your application:
- Start nRF Connect for Desktop. The launcher finds all apps in
~/.nrfconnect-apps/localand, using thepackage.jsonin your project, picks up thedist/bundle.jsthat was built before. - Look for your app in the list with a “local” tag under its name.
- Launch the app.
When you edit the source of the app and it is recompiled, press Ctrl-R (Windows or Linux) or Cmd-R (macOS) in the running app window to reload it.
Chrome Developer Tools can be opened by pressing Ctrl-Alt-I (Windows or Linux) or Cmd-Option-I (macOS).
Testing
You can use the following commands for testing:
npm run check- For running static checks like linting and type checkingnpm test- For unit tests
Distributing development versions
To distribute your development version of an app to others, run
npm pack.
This command creates a file that you can send to others so that they can
install that app locally. For example, for the pc-nrfconnect-boilerplate app, the file will be named pc-nrfconnect-boilerplate-0.0.1.tgz.