gavinr-maps / esri-svelte-example

An example web application that shows how to use the ArcGIS API for JavaScript with Svelte
https://esri-svelte-example.gavinr.com
Apache License 2.0
15 stars 5 forks source link

Local Assets Path #14

Open gavinr opened 3 years ago

gavinr commented 3 years ago

After #13, things are feeling pretty clean, but the built app still reaches out to js.arcgis.com for assets:

image

... which is OK in most cases but may be an issue for some users. It would be nice to update the example to use the assetsPath property per https://developers.arcgis.com/javascript/latest/es-modules/#working-with-assets (maybe using ncp package, if necessary) to avoid any requests going to js.arcgis.com.

odoe commented 3 years ago

The CDN assets are our current recommended way of loading assets. Doing the local copy of assets will probably add to build times (dev and prod) and larger deployed sizes. Maybe you can add a readme note on how to do the local copy if needed, but I think you should leave the CDN assets as default.

gavinr commented 3 years ago

Thank you very much for that clarification @odoe. Now that I am reading this more critically:

For most local builds, the API's assets are pulled from the ArcGIS CDN at runtime and there is no need for additional configuration. The assets include styles, images, fonts and localization files. This behavior is based on the default setting for config.assetsPath. https://developers.arcgis.com/javascript/latest/es-modules/#working-with-assets

... I do see how it implies that the recommended approach is to allow the assets to load from the CDN

jwasilgeo commented 2 years ago

I'm now revisiting this topic as I'm faced with a project where we have to rely totally on locally managed assets. No CDN chatter allowed.

Firing up ncp and setting up the esriConig.assetsPath property all checks out to me, but have either of you figured out where to copy ArcGIS ESM assets with Vite?

The Vite docs about static assets https://vitejs.dev/guide/assets.html provide both great explanations along with interesting caveats. Maybe the /public folder isn't quite the right spot? But if it is, I don't know how we'd have this line esriConfig.assetsPath = "./assets"; point to the correct place if you're in dev mode or building for production (where it all ends up shifted to the /dist folder).

Perhaps we'd rely on env vars? https://vitejs.dev/guide/env-and-mode.html#env-variables

jwasilgeo commented 2 years ago

UPDATE: I think I've figured out the right combo and will report back with some notes once I just verify a few more things.

am-maneaters commented 2 years ago

@jwasilgeo not sure if you can even see this, but if so, how did you end up using static assets in Vite? or @gavinr, were you ever able to get static assets working in Vite?

jwasilgeo commented 2 years ago

@samMatenaer as I recall it is doable. I think when I wrote the earlier comments/investigation above something wasn't that clear to me but then it started to click eventually. (I regret not updating this thread afterwards though.) I think it came down to each 3rd party library involved (3rd party from the perspective of Vite) might need its own handholding depending on certain criteria. Vite itself is great though. There should be some examples floating around in EsriPS I think? @gavinr @dhatcher