DEV Community

Discussion on: What the heck are CJS, AMD, UMD, and ESM in Javascript?

Collapse
 
salimkafin profile image
kafin

in this part, which you say can run in browser:

<script type="module">
  import {func1} from 'my-lib';

  func1();
</script>
Enter fullscreen mode Exit fullscreen mode

where do it get my-lib from?

Collapse
 
iggredible profile image
Igor Irianto

You can have local file that exports func1, say a js file 'my-lib.js' .

Then your import becomes :

 import {func1} from './my-lib.js';
Enter fullscreen mode Exit fullscreen mode

inside my-lib.js, have something like:

export function func1() {
  return `Hello func1!`;
}
Enter fullscreen mode Exit fullscreen mode