This repo demonstrates how to use the @arcgis/core ES modules with webpack.
-
[July 2022] If you are using Webpack
4and experiencingModule parse failed: Unexpected token. You may need an appropriate loader to handle this file type...errors during your build process after upgrading to ArcGIS API for JavaScript4.24+, then try the following steps.API version
4.24is the first version to use ES2020 optional chaining and nullish coalescing operators. These steps can help resolve parsing errors with older versions of Webpack:-
Install or upgrade these depedencies:
Command-line
npm install -D @babel/core @babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining babel-loaderpackage.json
"@babel/core": "^7.18.9", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", "@babel/plugin-proposal-optional-chaining": "^7.18.9", "babel-loader": "^8.2.5",
-
Add the following to your Webpack config:
webpack.config.js
module: { rules: [ { test: /\.m?js$/, exclude: { and: [/node_modules/], // exclude libraries in node_modules ... not: [ // except for ones that needs to be transpiled because they use modern syntax /@arcgis[\\/]core/ ] }, use: { loader: "babel-loader", options: { plugins: [ // these are required by Webpack 4 since @arcgis/core@4.24 ["@babel/plugin-proposal-nullish-coalescing-operator", { loose: true }], ["@babel/plugin-proposal-optional-chaining", { loose: true }] ] } } } ] } }; -
-
webpack-dev-serverhad a breaking change in4.0.0which removedcontentBasein favor of thestaticoption. This sample has been changed accordingly.
Step 1 - Run npm install and then start adding modules.
Step 2 Configure CSS. Here's a basic CSS example:
index.css
@import 'https://js.arcgis.com/4.25/@arcgis/core/assets/esri/themes/light/main.css';For additional information, see the Build with ES modules Guide topic in the SDK.
For a list of all available npm commands see the scripts in package.json.