From c7aa4f83bae724e07fe0a2e087e9bbc8f039152f Mon Sep 17 00:00:00 2001 From: Tsukina-7mochi <tsukina7mochi@gmail.com> Date: Tue, 30 Jan 2024 19:49:36 +0900 Subject: [PATCH] chore: add example of lodash via jsdelivr --- example/loadsh-jsdelivr/.gitignore | 1 + example/loadsh-jsdelivr/build.ts | 21 +++++++ example/loadsh-jsdelivr/deno.json | 7 +++ example/loadsh-jsdelivr/deno.lock | 82 +++++++++++++++++++++++++ example/loadsh-jsdelivr/import_map.json | 5 ++ example/loadsh-jsdelivr/index.ts | 6 ++ example/loadsh-jsdelivr/readme.md | 19 +----- 7 files changed, 124 insertions(+), 17 deletions(-) create mode 100644 example/loadsh-jsdelivr/.gitignore create mode 100644 example/loadsh-jsdelivr/build.ts create mode 100644 example/loadsh-jsdelivr/deno.json create mode 100644 example/loadsh-jsdelivr/deno.lock create mode 100644 example/loadsh-jsdelivr/import_map.json create mode 100644 example/loadsh-jsdelivr/index.ts diff --git a/example/loadsh-jsdelivr/.gitignore b/example/loadsh-jsdelivr/.gitignore new file mode 100644 index 0000000..ad2b62a --- /dev/null +++ b/example/loadsh-jsdelivr/.gitignore @@ -0,0 +1 @@ +/bundle.js diff --git a/example/loadsh-jsdelivr/build.ts b/example/loadsh-jsdelivr/build.ts new file mode 100644 index 0000000..bf1f444 --- /dev/null +++ b/example/loadsh-jsdelivr/build.ts @@ -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(); diff --git a/example/loadsh-jsdelivr/deno.json b/example/loadsh-jsdelivr/deno.json new file mode 100644 index 0000000..6c0521e --- /dev/null +++ b/example/loadsh-jsdelivr/deno.json @@ -0,0 +1,7 @@ +{ + "importMap": "import_map.json", + "tasks": { + "build": "deno run -A build.ts", + "cache": "rm deno.lock && deno cache **/*.ts" + } +} diff --git a/example/loadsh-jsdelivr/deno.lock b/example/loadsh-jsdelivr/deno.lock new file mode 100644 index 0000000..63d74a4 --- /dev/null +++ b/example/loadsh-jsdelivr/deno.lock @@ -0,0 +1,82 @@ +{ + "version": "3", + "redirects": { + "https://esm.sh/loadsh": "https://esm.sh/loadsh@0.0.4" + }, + "remote": { + "https://cdn.jsdelivr.net/npm/lodash/+esm": "3914432e5f193fef3f3c1bb2c60de006b2a9ffea7886978a884ea276f7a5cbc7", + "https://deno.land/std@0.203.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", + "https://deno.land/std@0.203.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", + "https://deno.land/std@0.203.0/crypto/_fnv/fnv32.ts": "e4649dfdefc5c987ed53c3c25db62db771a06d9d1b9c36d2b5cf0853b8e82153", + "https://deno.land/std@0.203.0/crypto/_fnv/fnv64.ts": "bfa0e4702061fdb490a14e6bf5f9168a22fb022b307c5723499469bfefca555e", + "https://deno.land/std@0.203.0/crypto/_fnv/mod.ts": "f956a95f58910f223e420340b7404702ecd429603acd4491fa77af84f746040c", + "https://deno.land/std@0.203.0/crypto/_fnv/util.ts": "accba12bfd80a352e32a872f87df2a195e75561f1b1304a4cb4f5a4648d288f9", + "https://deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs": "85b50eee2e511584698c04f1d84155e57452ea963106fee64987c326e9e5d25d", + "https://deno.land/std@0.203.0/crypto/_wasm/mod.ts": "973058e70052c98292b567d1c8396dffc28d6dfc6a44f0763032f6fbdf5222f5", + "https://deno.land/std@0.203.0/crypto/crypto.ts": "c1fac13f11e5150e7690a4d6f09bc09b39d0a13fc5cf129f13617656fea7379e", + "https://deno.land/std@0.203.0/crypto/keystack.ts": "cec9ddf60e0c0c9970360e66c9402afb3c0c68bcd50ef19c68daf63f94e40863", + "https://deno.land/std@0.203.0/crypto/mod.ts": "ae384519e85eca9aeff4e7111ed153df8f3dbda7b35b70850ed4b3e9c8cec4d5", + "https://deno.land/std@0.203.0/crypto/timing_safe_equal.ts": "f6edc08d702f660b1ab3505b74d53a9d499e34a1351f6ab70f5ce8653fee8fb7", + "https://deno.land/std@0.203.0/crypto/to_hash_string.ts": "c78050f72a9d4a690d85e83a85a43c2951d23a04d5b2a4537b2ebc00854421be", + "https://deno.land/std@0.203.0/crypto/unstable/keystack.ts": "624c2f2d8fa6711d44fcb8fbca346e7fb56afa7aa3fcf2d8e6db32978e9fbac2", + "https://deno.land/std@0.203.0/encoding/_util.ts": "f368920189c4fe6592ab2e93bd7ded8f3065b84f95cd3e036a4a10a75649dcba", + "https://deno.land/std@0.203.0/encoding/base64.ts": "cc03110d6518170aeaa68ec97f89c6d6e2276294b30807e7332591d7ce2e4b72", + "https://deno.land/std@0.203.0/encoding/base64url.ts": "8f7e073b02175581a978e36a27fac97e80ad1e1ca2ddbfc6d13b6be7a8ab5faa", + "https://deno.land/std@0.203.0/encoding/hex.ts": "d41e9c3f7dd9d4738c40c2b9e6db5eb32e9dc103360291aff63a5c3fccdb45a6", + "https://deno.land/std@0.203.0/fs/_util.ts": "fbf57dcdc9f7bc8128d60301eece608246971a7836a3bb1e78da75314f08b978", + "https://deno.land/std@0.203.0/fs/copy.ts": "23cc1c465babe5ca4d69778821e2f8addc44593e30a5ca0b902b3784eed75bb6", + "https://deno.land/std@0.203.0/fs/empty_dir.ts": "2e52cd4674d18e2e007175c80449fc3d263786a1361e858d9dfa9360a6581b47", + "https://deno.land/std@0.203.0/fs/ensure_dir.ts": "dc64c4c75c64721d4e3fb681f1382f803ff3d2868f08563ff923fdd20d071c40", + "https://deno.land/std@0.203.0/fs/ensure_file.ts": "39ac83cc283a20ec2735e956adf5de3e8a3334e0b6820547b5772f71c49ae083", + "https://deno.land/std@0.203.0/fs/ensure_link.ts": "c15e69c48556d78aae31b83e0c0ece04b7b8bc0951412f5b759aceb6fde7f0ac", + "https://deno.land/std@0.203.0/fs/ensure_symlink.ts": "b389c8568f0656d145ac7ece472afe710815cccbb2ebfd19da7978379ae143fe", + "https://deno.land/std@0.203.0/fs/eol.ts": "f1f2eb348a750c34500741987b21d65607f352cf7205f48f4319d417fff42842", + "https://deno.land/std@0.203.0/fs/exists.ts": "cb59a853d84871d87acab0e7936a4dac11282957f8e195102c5a7acb42546bb8", + "https://deno.land/std@0.203.0/fs/expand_glob.ts": "52b8b6f5b1fa585c348250da1c80ce5d820746cb4a75d874b3599646f677d3a7", + "https://deno.land/std@0.203.0/fs/mod.ts": "bc3d0acd488cc7b42627044caf47d72019846d459279544e1934418955ba4898", + "https://deno.land/std@0.203.0/fs/move.ts": "b4f8f46730b40c32ea3c0bc8eb0fd0e8139249a698883c7b3756424cf19785c9", + "https://deno.land/std@0.203.0/fs/walk.ts": "a16146724a6aaf9efdb92023a74e9805195c3469900744ce5de4113b07b29779", + "https://deno.land/std@0.203.0/path/_basename.ts": "057d420c9049821f983f784fd87fa73ac471901fb628920b67972b0f44319343", + "https://deno.land/std@0.203.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", + "https://deno.land/std@0.203.0/path/_dirname.ts": "355e297236b2218600aee7a5301b937204c62e12da9db4b0b044993d9e658395", + "https://deno.land/std@0.203.0/path/_extname.ts": "eaaa5aae1acf1f03254d681bd6a8ce42a9cb5b7ff2213a9d4740e8ab31283664", + "https://deno.land/std@0.203.0/path/_format.ts": "4a99270d6810f082e614309164fad75d6f1a483b68eed97c830a506cc589f8b4", + "https://deno.land/std@0.203.0/path/_from_file_url.ts": "6eadfae2e6f63ad9ee46b26db4a1b16583055c0392acedfb50ed2fc694b6f581", + "https://deno.land/std@0.203.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", + "https://deno.land/std@0.203.0/path/_is_absolute.ts": "05dac10b5e93c63198b92e3687baa2be178df5321c527dc555266c0f4f51558c", + "https://deno.land/std@0.203.0/path/_join.ts": "815f5e85b042285175b1492dd5781240ce126c23bd97bad6b8211fe7129c538e", + "https://deno.land/std@0.203.0/path/_normalize.ts": "a19ec8706b2707f9dd974662a5cd89fad438e62ab1857e08b314a8eb49a34d81", + "https://deno.land/std@0.203.0/path/_os.ts": "30b0c2875f360c9296dbe6b7f2d528f0f9c741cecad2e97f803f5219e91b40a2", + "https://deno.land/std@0.203.0/path/_parse.ts": "0f9b0ff43682dd9964eb1c4398610c4e165d8db9d3ac9d594220217adf480cfa", + "https://deno.land/std@0.203.0/path/_relative.ts": "27bdeffb5311a47d85be26d37ad1969979359f7636c5cd9fcf05dcd0d5099dc5", + "https://deno.land/std@0.203.0/path/_resolve.ts": "7a3616f1093735ed327e758313b79c3c04ea921808ca5f19ddf240cb68d0adf6", + "https://deno.land/std@0.203.0/path/_to_file_url.ts": "a141e4a525303e1a3a0c0571fd024552b5f3553a2af7d75d1ff3a503dcbb66d8", + "https://deno.land/std@0.203.0/path/_to_namespaced_path.ts": "0d5f4caa2ed98ef7a8786286df6af804b50e38859ae897b5b5b4c8c5930a75c8", + "https://deno.land/std@0.203.0/path/_util.ts": "4e191b1bac6b3bf0c31aab42e5ca2e01a86ab5a0d2e08b75acf8585047a86221", + "https://deno.land/std@0.203.0/path/basename.ts": "bdfa5a624c6a45564dc6758ef2077f2822978a6dbe77b0a3514f7d1f81362930", + "https://deno.land/std@0.203.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", + "https://deno.land/std@0.203.0/path/dirname.ts": "b6533f4ee4174a526dec50c279534df5345836dfdc15318400b08c62a62a39dd", + "https://deno.land/std@0.203.0/path/extname.ts": "62c4b376300795342fe1e4746c0de518b4dc9c4b0b4617bfee62a2973a9555cf", + "https://deno.land/std@0.203.0/path/format.ts": "110270b238514dd68455a4c54956215a1aff7e37e22e4427b7771cefe1920aa5", + "https://deno.land/std@0.203.0/path/from_file_url.ts": "9f5cb58d58be14c775ec2e57fc70029ac8b17ed3bd7fe93e475b07280adde0ac", + "https://deno.land/std@0.203.0/path/glob.ts": "593e2c3573883225c25c5a21aaa8e9382a696b8e175ea20a3b6a1471ad17aaed", + "https://deno.land/std@0.203.0/path/is_absolute.ts": "0b92eb35a0a8780e9f16f16bb23655b67dace6a8e0d92d42039e518ee38103c1", + "https://deno.land/std@0.203.0/path/join.ts": "31c5419f23d91655b08ec7aec403f4e4cd1a63d39e28f6e42642ea207c2734f8", + "https://deno.land/std@0.203.0/path/mod.ts": "6e1efb0b13121463aedb53ea51dabf5639a3172ab58c89900bbb72b486872532", + "https://deno.land/std@0.203.0/path/normalize.ts": "6ea523e0040979dd7ae2f1be5bf2083941881a252554c0f32566a18b03021955", + "https://deno.land/std@0.203.0/path/parse.ts": "be8de342bb9e1924d78dc4d93c45215c152db7bf738ec32475560424b119b394", + "https://deno.land/std@0.203.0/path/posix.ts": "0a1c1952d132323a88736d03e92bd236f3ed5f9f079e5823fae07c8d978ee61b", + "https://deno.land/std@0.203.0/path/relative.ts": "8bedac226afd360afc45d451a6c29fabceaf32978526bcb38e0c852661f66c61", + "https://deno.land/std@0.203.0/path/resolve.ts": "133161e4949fc97f9ca67988d51376b0f5eef8968a6372325ab84d39d30b80dc", + "https://deno.land/std@0.203.0/path/separator.ts": "40a3e9a4ad10bef23bc2cd6c610291b6c502a06237c2c4cd034a15ca78dedc1f", + "https://deno.land/std@0.203.0/path/to_file_url.ts": "00e6322373dd51ad109956b775e4e72e5f9fa68ce2c6b04e4af2a6eed3825d31", + "https://deno.land/std@0.203.0/path/to_namespaced_path.ts": "1b1db3055c343ab389901adfbda34e82b7386bcd1c744d54f9c1496ee0fd0c3d", + "https://deno.land/std@0.203.0/path/win32.ts": "8b3f80ef7a462511d5e8020ff490edcaa0a0d118f1b1e9da50e2916bdd73f9dd", + "https://deno.land/x/denoflate@1.2.1/mod.ts": "f5628e44b80b3d80ed525afa2ba0f12408e3849db817d47a883b801f9ce69dd6", + "https://deno.land/x/denoflate@1.2.1/pkg/denoflate.js": "b9f9ad9457d3f12f28b1fb35c555f57443427f74decb403113d67364e4f2caf4", + "https://deno.land/x/denoflate@1.2.1/pkg/denoflate_bg.wasm.js": "d581956245407a2115a3d7e8d85a9641c032940a8e810acbd59ca86afd34d44d", + "https://deno.land/x/esbuild@v0.19.4/mod.js": "6277018cfbcad3912fd346409e0b2a9807cf10c9555a15e4aac299b3194fa4fb", + "https://esm.sh/loadsh@0.0.4": "1b6ed5ec4c928bd19b9cf98fc55d0901c5b51afd94761587df70933ae0643a3c", + "https://esm.sh/v133/loadsh@0.0.4/denonext/loadsh.mjs": "a517db532d7f626e923b3084fe47585f20652de303ceb338636e682ba8fe2154" + } +} diff --git a/example/loadsh-jsdelivr/import_map.json b/example/loadsh-jsdelivr/import_map.json new file mode 100644 index 0000000..f85d2bb --- /dev/null +++ b/example/loadsh-jsdelivr/import_map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "lodash": "https://cdn.jsdelivr.net/npm/lodash/+esm" + } +} diff --git a/example/loadsh-jsdelivr/index.ts b/example/loadsh-jsdelivr/index.ts new file mode 100644 index 0000000..5d44c2e --- /dev/null +++ b/example/loadsh-jsdelivr/index.ts @@ -0,0 +1,6 @@ +import _ from 'lodash'; + +console.log(_.merge( + { a: { b: 0 } }, + { a: { c: 1 }, d: 2 }, +)); diff --git a/example/loadsh-jsdelivr/readme.md b/example/loadsh-jsdelivr/readme.md index 0c3e198..19a49cc 100644 --- a/example/loadsh-jsdelivr/readme.md +++ b/example/loadsh-jsdelivr/readme.md @@ -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`.)