Is there a way to not have all locales in my package?

1343
9
02-15-2022 06:09 AM
sandrooco
New Contributor II

Hello everybody

I'm using @arcgis/core. When building the project, there are countless (all?) locales/translations loaded. Is there a way to only bundle the locales that I really want instead of all?

I'd be great if there was a param in `esriConfig` for example.

Thanks!

Tags (3)
0 Kudos
9 Replies
ReneRubalcava
Frequent Contributor

This will depend on your build environment. We have a webpack-plugin that will simplify this for you.

https://github.com/Esri/arcgis-webpack-plugin

// webpack.config.js
module.exports = {
  ...
  plugins: [
    new ArcGISPlugin({
      locales: ['en', 'es']
    })
  ]
  ...
}

 

If you're not using webpack, or don't want to use the plugin (the asset copy/filter functionality is all it really offers in most cases) you can mimic what the plugin does in your own application.

This is how it will filter the the locale files in the copy operation.

https://github.com/Esri/arcgis-webpack-plugin/blob/master/lib/requiredPlugins.js#L50-L73

 

sandrooco
New Contributor II

Hi Rene, thanks for your help.

This strangely didn't work.. I was able to add the plugin and it's recognized, but the translation chunks still show up.. Do you have any other ideas?

0 Kudos
ReneRubalcava
Frequent Contributor

Do you have a repo? I tried this out looking at the doc to let the plugin copy the assets and this work.

new ArcGISPlugin({
  locales: ['en', 'es']
}),

ReneRubalcava_0-1645635684070.png

 

 

0 Kudos
sandrooco
New Contributor II

I don't have an example repo that I could post publicly at the moment.
We use Angular and injected the custom webpack bit via @angular-builders/custom-webpack. Do you have any Angular examples?

0 Kudos
ReneRubalcava
Frequent Contributor

I don't know Angular well enough to say, @AndyGup might have an idea.

Maybe you can tweak the assets copy glob to do it simpler.

Something like what is done in the plugin here https://github.com/Esri/arcgis-webpack-plugin/blob/master/lib/requiredPlugins.js#L67

  "assets": [
    {
      "glob": "**/*", // update the glob here to ignore locales
      "input": "node_modules/@arcgis/core/assets",
      "output": "/assets/"
    },
  ],
0 Kudos
AndyGup
Esri Regular Contributor

Hi@sandrooco let us know what version of Angular?

Here's an example using Angular 11 with a custom builder and the ArcGIS webpack plugin: https://github.com/andygup/angular-cli-esri-map/tree/arcgis-webpack-angular . The repo is archived and it uses the AMD modules, but hopefully you can reuse some of the builder patterns to get the plugin working.

0 Kudos
sandrooco
New Contributor II

Hi @AndyGup, thanks for your input.
I set up my project the same like yours, it's on Angular 13 though (shouldn't make a difference).

Could you please try with this and check what chunks are produced?

 locales: ['en', 'es']

 

0 Kudos
AndyGup
Esri Regular Contributor

Sure @sandrooco I can take a look, it'll probably be next week. Do you have a requirement to keep the assets local? By default they'll pull from CDN, reference: https://developers.arcgis.com/javascript/latest/es-modules/#working-with-assets.

0 Kudos
sandrooco
New Contributor II

That would be cool, thanks.
It's not a must to have it locally but would be nice because we could lazy load it like our other components/modules.

0 Kudos