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

Commit c7aa4f8

Browse files
chore: add example of lodash via jsdelivr
1 parent 4306035 commit c7aa4f8

File tree

7 files changed

+124
-17
lines changed

7 files changed

+124
-17
lines changed

example/loadsh-jsdelivr/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bundle.js

example/loadsh-jsdelivr/build.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { esbuild } from '../../deps.ts';
2+
import esbuildCachePlugin from '../../mod.ts';
3+
4+
const importMap = JSON.parse(Deno.readTextFileSync('./import_map.json'));
5+
const lockMap = JSON.parse(Deno.readTextFileSync('./deno.lock'));
6+
7+
const denoPath = await esbuildCachePlugin.util.getDenoDir();
8+
await esbuild.build({
9+
entryPoints: ['./index.ts'],
10+
bundle: true,
11+
outfile: './bundle.js',
12+
plugins: [
13+
esbuildCachePlugin({
14+
denoCacheDirectory: denoPath,
15+
lockMap,
16+
importMap,
17+
}),
18+
],
19+
});
20+
21+
await esbuild.stop();

example/loadsh-jsdelivr/deno.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"importMap": "import_map.json",
3+
"tasks": {
4+
"build": "deno run -A build.ts",
5+
"cache": "rm deno.lock && deno cache **/*.ts"
6+
}
7+
}

example/loadsh-jsdelivr/deno.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"lodash": "https://cdn.jsdelivr.net/npm/lodash/+esm"
4+
}
5+
}

example/loadsh-jsdelivr/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import _ from 'lodash';
2+
3+
console.log(_.merge(
4+
{ a: { b: 0 } },
5+
{ a: { c: 1 }, d: 2 },
6+
));

example/loadsh-jsdelivr/readme.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
# Example: Import Map
1+
# Example: Lodash from jsDelivr
22

3-
You can use import maps to map imports with `importMap` option:
4-
5-
```javascript
6-
esbuildCachePlugin({
7-
importMap: {
8-
"imports": {
9-
"https://example.com/foo/": "./src/polyfill/foo/"
10-
},
11-
"scopes": {
12-
"./src/foo.ts": {
13-
"https://example.com/foo/": "./src/polyfill/bar/"
14-
}
15-
}
16-
},
17-
}),
18-
```
3+
Using Lodash from jsDelivr, mapping `lodash` to remote URL (see `import_map.json`.)

0 commit comments

Comments
 (0)