Skip to content

Instantly share code, notes, and snippets.

@ugultopu
Created October 25, 2020 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugultopu/ee6e890bd9261257bf9a35f75603e71d to your computer and use it in GitHub Desktop.
Save ugultopu/ee6e890bd9261257bf9a35f75603e71d to your computer and use it in GitHub Desktop.
npm packages written with ES modules can be used in browsers without extra set up
<!DOCTYPE html>
<html>
<head>
<script type="module">
// Note that it has to be "lodash-es". Just "lodash" does not work
// because just "lodash" uses CommonJS modules (that is, Node.JS
// modules), which are not implemented in (web) browsers.
import cloneDeep from 'https://cdn.jsdelivr.net/npm/lodash-es@4.17.15/cloneDeep.js';
function log(object) {
console.log(cloneDeep(object));
}
const a = { a: [1,2,3,4] };
for (let i = 0; i < a.a.length; i++) {
a.a[i] = -1;
log(a);
}
</script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment