Best practice for importing script for a package
Hi ! I am making a community package for Convex by wrapping Convex 's plain JavaScript library (inspired by their Svelte package ) . The documentation for the library can be found here : https://docs.convex.dev/quickstart/script-tag According to the docs , they recommend adding a script tag to unpkg https://unpkg.com/convex@1.3.1/dist/browser.bundle.js as such : <!doctype html>
<script src="https://unpkg.com/convex@1.3.1/dist/browser.bundle.js"></script>
<script>
const CONVEX_URL = "CONVEX_URL_GOES_HERE";
const client = new convex.ConvexClient(CONVEX_URL);
client.onUpdate("tasks:get", {}, (tasks) =>
console.log(tasks.map((task) => task.text)),
);
</script>This works in Nord by modifying the page external resources , but the problem is as a package , I don 't think it 's very reasonable for the end user to have to add the script every page manually . I tried importing an ESM variant through JSDelivr via a Nord action , but the imported module seems to be empty : https://cdn.jsdelivr.net/npm/convex@1.23.0/+esm Honestly I would prefer going about an import() the ESM way , but what 's the right module to import ? The import I 'm interested in is convex/browser (which contains ConvexClient , for example ) . Thanks 🙂 ✅1Actual 'thing ' depends on the package Again , it depends on the package and how you 're using it Ok this works ! const convex = await import("https://cdn.jsdelivr.net/npm/convex@1.23.0/dist/esm/browser/index.js/+esm") The trouble was finding the right path . I found it by going to https://cdn.jsdelivr.net/npm/convex@1.23.0/ then navigating to dist /esm /browser /index .js . Then just appending /+esm made it compatible . Thanks ! ✅1