Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build ES modules for public CDN #788

Closed
patrickarlt opened this issue Dec 17, 2020 · 3 comments · Fixed by #911
Closed

Build ES modules for public CDN #788

patrickarlt opened this issue Dec 17, 2020 · 3 comments · Fixed by #911
Milestone

Comments

@patrickarlt
Copy link
Contributor

I would love to be able to write examples in pure ES modules without a compiler and publish them on the CDN.

<script type="module">
import { request } from "https://unpkg.com/@esri/arcgis-rest-request@3.0.0/dist/esm/request.es.min.js"

request({
  // ...
});
</script>

Or via import maps https://github.com/WICG/import-maps

<script type="importmap">
{
  "imports": {
    "@esri/arcgis-rest-request": "https://unpkg.com/@esri/arcgis-rest-request@3.0.0/dist/esm/request.es.min.js",
  }
}
</script>

<script type="module">
import { request } from "@esri/arcgis-rest-request"

request({
  // ...
});
</script>

It would probally take a bit of R & D to figure out how to make Typescript do this.

@patrickarlt patrickarlt added this to the v3.0 milestone Dec 17, 2020
@jgravois
Copy link
Contributor

jgravois commented Dec 22, 2020

greetings friends! 👋

i don't know what kind of 🤸 it would take to get the TypeScript compiler to generate flat ES Module output, but it doesn't take much to convince rollup to do it.

jgravois@3f51b77

prior art: https://github.com/terraformer-js/terraformer/tree/master/packages/arcgis#es-module-in-the-browser

@patrickarlt
Copy link
Contributor Author

patrickarlt commented Sep 7, 2021

@jgravois Thanks for the tip. I was going down this path but I hate that we end up with duplicating arcgis-rest-request in every package. Similarly it doesn't look like import maps are ready for prime time yet https://caniuse.com/?search=importmap so we cant solve this without a size and performance caveat like the JS API.

However I did find https://www.skypack.dev/ which basically looks like Unpkg for ES Modules. The best part it that it already works with our existing release AND doesn't seem to duplicate arcgis-rest-request https://codepen.io/patrickarlt/pen/QWgdwWM

<script type="module">
import {request} from "  https://cdn.skypack.dev/@esri/arcgis-rest-request@3.3.0?min"
import {createGroup} from "  https://cdn.skypack.dev/@esri/arcgis-rest-portal@3.3.0?min"

console.log({request, createGroup});
</script>

2021-09-07_10-17-29

I think going forward we can just continue as we are with my 4.0 build refactor and point people to Skypack for ES modules and Unpkg for everything else without any extra builds or configuration.

@patrickarlt
Copy link
Contributor Author

Looks like Skypack will also "pin" production ready URLs for us when we do a lookup https://docs.skypack.dev/skypack-cdn/api-reference/pinned-urls-optimized so we can/should call Skypack when we do a ready and we can generate the pinned URLS and include them in the doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants