Last active
January 16, 2025 19:29
-
-
Save ashtonmeuser/39e0cb3f2472cb8980726fb6c7d6d349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bookmarklet-title: ESM Imports | |
// bookmarklet-about: Test esbuild custom module resolution | |
// The following dependencies use static imports | |
// They are bundled with the bookmarklet (thereby increasing bundle size) | |
// Relative imports will resolve to files within the same gist | |
import { v4 as uuidRemoteStatic } from 'https://esm.sh/[email protected]'; | |
console.log('UUID from remote static:', uuidRemoteStatic()); | |
import uuidRelativeStatic from './export.ts'; | |
console.log('UUID from relative static:', uuidRelativeStatic()); | |
import uuidRelativeStaticDeeper from './exportDeeper.ts'; | |
console.log('UUID from relative static deeper:', uuidRelativeStaticDeeper()); | |
import _ from 'https://cdn.jsdelivr.net/npm/@esm-bundle/[email protected]/+esm'; | |
console.log('Lodash test:', _.chunk([1, 2, 3, 4], [2])); | |
import axios from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; | |
console.log('Axios test:', axios.isCancel(new axios.Cancel('test'))); | |
import * as cheerio from 'https://esm.sh/cheerio'; | |
console.log('Cheerio test:', cheerio.load('<ul id="fruits">...</ul>').html()); | |
// The following static imports demonstrate loading different types of content | |
// Note that a custom loader can be defined using the loader import attribute | |
import css from './test.css'; | |
console.log('CSS:', css); | |
import html from './test.html'; | |
console.log('HTML:', html); | |
import data from './test.dat'; | |
console.log('Data:', data); | |
import json from './test.json'; | |
console.log('JSON:', json); | |
import svg from './test.svg'; | |
console.log('SVG:', svg); | |
import png from 'https://placehold.co/10x10.png'; | |
console.log('PNG:', png); | |
import base64 from 'https://placehold.co/10x10.png' with { loader: 'base64' }; | |
console.log('PNG (custom loader):', base64); | |
// The following dependencies use dynamic imports | |
// Therefore, they are not bundled with the bookmarklet | |
// Rather, they are fetched on bookmarklet evaluation | |
// Note that relative imports can still be used | |
(async () => { | |
const { v4: uuidRemoteDynamic } = await import('https://esm.sh/[email protected]'); | |
console.log('UUID from remote dynamic:', uuidRemoteDynamic()); | |
const { default: uuidRelativeDynamic } = await import('./export.ts'); | |
console.log('UUID from relative dynamic:', uuidRelativeDynamic()); | |
const { default: uuidRelativeDynamicDeeper } = await import('./exportDeeper.ts'); | |
console.log('UUID from relative dynamic deeper:', uuidRelativeDynamicDeeper()); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { v4 } from 'https://esm.sh/[email protected]'; | |
export default () => v4(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { v4 } from 'https://esm.sh/[email protected]'; | |
export default () => v4(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import v4 from './deeper.ts'; | |
export default () => v4(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
color: red; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
Hello, World! | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"string": "test", | |
"array": [0, 1, 2, 3] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment