Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
chore: add example of lodash via jsdelivr
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsukina-7mochi committed Jan 30, 2024
1 parent 4306035 commit c7aa4f8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 17 deletions.
1 change: 1 addition & 0 deletions example/loadsh-jsdelivr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bundle.js
21 changes: 21 additions & 0 deletions example/loadsh-jsdelivr/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { esbuild } from '../../deps.ts';
import esbuildCachePlugin from '../../mod.ts';

const importMap = JSON.parse(Deno.readTextFileSync('./import_map.json'));
const lockMap = JSON.parse(Deno.readTextFileSync('./deno.lock'));

const denoPath = await esbuildCachePlugin.util.getDenoDir();
await esbuild.build({
entryPoints: ['./index.ts'],
bundle: true,
outfile: './bundle.js',
plugins: [
esbuildCachePlugin({
denoCacheDirectory: denoPath,
lockMap,
importMap,
}),
],
});

await esbuild.stop();
7 changes: 7 additions & 0 deletions example/loadsh-jsdelivr/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"importMap": "import_map.json",
"tasks": {
"build": "deno run -A build.ts",
"cache": "rm deno.lock && deno cache **/*.ts"
}
}
82 changes: 82 additions & 0 deletions example/loadsh-jsdelivr/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/loadsh-jsdelivr/import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"lodash": "https://cdn.jsdelivr.net/npm/lodash/+esm"
}
}
6 changes: 6 additions & 0 deletions example/loadsh-jsdelivr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import _ from 'lodash';

console.log(_.merge(
{ a: { b: 0 } },
{ a: { c: 1 }, d: 2 },
));
19 changes: 2 additions & 17 deletions example/loadsh-jsdelivr/readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# Example: Import Map
# Example: Lodash from jsDelivr

You can use import maps to map imports with `importMap` option:

```javascript
esbuildCachePlugin({
importMap: {
"imports": {
"https://example.com/foo/": "./src/polyfill/foo/"
},
"scopes": {
"./src/foo.ts": {
"https://example.com/foo/": "./src/polyfill/bar/"
}
}
},
}),
```
Using Lodash from jsDelivr, mapping `lodash` to remote URL (see `import_map.json`.)

0 comments on commit c7aa4f8

Please sign in to comment.