Created
October 25, 2020 00:33
-
-
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
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
<!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/[email protected]/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