0

I am using a --experimental-loader in node.js for a .mjs file. The command looks something like this:

node --experimental-loader=./loader.mjs ./demo.mjs

I wish to use the loader in the browser that supports import statement inside a ES script module <script type="module"></script>. The loader basically has a small modification.

<script type="module">

<!-- Need a loader to load before this like node.js -->
import { default as x } from "./bundle.js";

</script>
Gary
  • 2,293
  • 2
  • 25
  • 47

1 Answers1

0

The loader can be used in the browser by adding a type="module" attribute to the script tag, as follows:

<script type="module" src="./loader.mjs"></script>

This will tell the browser to use the loader for any subsequent import statements in the script.

Mohamed Elgazar
  • 778
  • 4
  • 9
  • You mean something like this: `` – Gary Oct 16 '22 at 16:16
  • @Gary You cannot combine both an `src` attribute and module code into the same ` – Sebastian Simon Oct 16 '22 at 16:22
  • Ok. I need to load a `loader.mjs` like I use with `--experimental-loader=./loader.mjs`. Any help with that? Is it even possible? – Gary Oct 16 '22 at 16:33