I am currently integrating ArcGIS into a small forms library I am building for an organization. My library is bundled into UMD, and then imported into a browser using a simple <script> tag like so :
@MindingData I'm working on a similar thing myself.
You can use the output.manualChunks option within the rollupOptions section of the vite configuration. (Vite uses rollup for the bundling.)
Here's an example of how you could split `@arcgis/core` into several smaller chunks in your vite.config.ts file:
import { defineConfig } from "vite";
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
const matchIndex = id.indexOf("@arcgis/core/");
if (matchIndex !== -1) {
const parts = id.substring(matchIndex).split("/");
if (parts.length === 3) {
// Immediate children of @arcgis/core are in the same chunk. (@arcgis-core)
parts.length = 2;
} else if (parts[2] === "views" && ["2d", "3d"].includes(parts[3])) {
// @arcgis/core/views/2d and @arcgis/core/views/3d are split into separate chunks.
parts.length = 4;
} else {
// Otherwise, chunk by the immediate subdirectory of @arcgis/core, e.g. @arcgis/core/layers.
parts.length = 3;
}
return parts.join("-");
}
return null;
},
},
},
},
});It's a work in progress, but the idea is that this will split out @arcgis/core into the following chunks:
I've still not decided if this is the best way to split it up. I had noticed "views" was quite big, which was why I added the extra steps of separating out 2d and 3d.
I think separating out ALL immediate children of arcgis-core might be too much. The one downside I've observed is that the more chunks you have, the more total code you end up with because other chunks need to import the individual parts.
There's likely a sweet spot where the individual chunks aren't too big and the consumers aren't too bloated as a result.