Visualization

Reference

Using npm for Custom Builds

Using npm (A package manager for JavaScript) is another option for developers of the JavaScript API to generate custom builds of the ArcGIS API for JavaScript. You would use the npm package of the ArcGIS API for JavaScript if you wanted to create local builds of your application.

Note: See the prerequisites section on configuring your system before proceeding. If your system is already configured with Git, Node.js, and Java you may proceed to the Getting Started section.

Understanding npm

You get npm when you install Node.js. It is package manager for JavaScript. In the provided npm sample, you are given you are given some npm scripts in the package.json as shortcuts for your development environment.

Note: If you are new to node and are unfamiliar or need a refresher on what is contained in a package.json file, please refer to the documentation.

In the Generate a custom build (Dojo), you will be asked to issue a command npm install. When npm install is invoked, it will install version 4.10 of the ArcGIS API for JavaScript locally, as well as any dependencies and/or devDependencies listed in the package.json file. See the package.json file in the dojo sample for more information.

All npm dependencies are downloaded to a folder called node_modules. Notice how we have a dependency for arcgis-js-api. This dependency will download the current version of the ArcGIS JS API package and its own predefined dependencies. You can see a list of the dependencies in the README for the package.

When everything is downloaded, you should have a similar folder structure. Now you have full access to the ArcGIS API for JavaScript and its dependencies.

The npm install sequence is where Grunt and the supporting plugins grunt-contrib-clean and grunt-contrib-copy are installed. The npm run clean sequence will remove the built files from the dist directory, and the npm run build command will run the Dojo build on the sample application. If you are interested in building the Sass files included in the npm release of the API, or creating a custom theme based upon one of the existing themes, please refer to this document.

Generate a custom build (Dojo)

For both options (clone or download), you need to copy the source files from https://github.com/Esri/jsapi-resources/tree/master/4.x/npm/demo to a new directory. In the following steps, we'll name the new directory esrijs-npm-dojo.

This tells the Dojo build system to build the dojo/dojo.js file and to include other files into it. This will become the entry point for your application. This will get you an optimized single-file that you can use to deploy your application. Please see the sample build profile for more details.