Get Started with webpack, Rollup or Parcel

ArcGIS REST JS works well with popular module bundlers like webpack, Rollup and Parcel.

If you need to support environments where fetch and Promise aren't already present, you can install polyfills for them.

npm install @esri/arcgis-rest-request

You can find npm install commands for all packages in the API reference.

import 'cross-fetch/polyfill';
import { request } from "@esri/arcgis-rest-request";

request("https://www.arcgis.com/sharing/rest/info")
  .then(response => {
    console.log(response);
  });

Tree Shaking

Bundlers like webpack and Rollup can statically analyze the code inside ArcGIS REST JS and exclude anything that isn't used. This is called dead-code elimination and it means rest-js won't bloat your bundle.

Its worth noting, to activate tree-shaking in webpack, production mode and usedExports optimization need to be enabled.

// webpack.config.js
module.exports = {
  // ...
  mode: 'production',
  optimization: {
    usedExports: true
  },
  // ...
}

Tree Shaking Demos

Note: many libraries and tools (such as Babel) require an ES6 Promise polyfill. Any Promise polyfill will work with ArcGIS REST JS, es6-promise is simply a lightweight standalone version.