#TIL : ES6 Module import in client browsers


29 Aug 2023 / by KhanhIceTea

moduleA.js

export const message = "Hello from moduleA!";

moduleB.js

import { message } from './moduleA.js';
console.log(message);

app.html

<script type="module" src="moduleB.js"></script>

// Print console log "Hello from moduleA!"

So moduleB.js acts like a module entry-point, it loads all dependencies deeply to run it-self, so you only need add script tag point to it.


Sound good ?