OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to use esbuild to build the bundle if importmap is used

  • Thread starter Thread starter Marcus
  • Start date Start date
M

Marcus

Guest
Possible to use esbuild to build the bundle if importmap is used?

Below is my esbuild build script, it shows Error: Could not resolve "mylib", but how can I tell esbuild about the importmap?

Code:
await esbuild.build({
  entryPoints: ['../src-js/main.js'],
  bundle: true,
  minify: true,
  format: 'esm',
  outdir: '../js',
  outbase: '../src-js',
});

html:

Code:
<script type="importmap">
  {
    "imports": {
      "mylib": "/src-js/my-lib.js"
    }
  }
</script>
<script type="module" src="/src-js/main.js"></script>

/src-js/my-lib.js:

Code:
export function say_hello() {
    alert('hello');
}

/src-js/main.js:

Code:
import { say_hello } from 'mylib';

document.addEventListener("DOMContentLoaded", (e) => {
    say_hello();
});

<p>Possible to use esbuild to build the bundle if importmap is used?</p>
<p>Below is my esbuild build script, it shows Error: Could not resolve "mylib", but how can I tell esbuild about the importmap?</p>
<pre><code>await esbuild.build({
entryPoints: ['../src-js/main.js'],
bundle: true,
minify: true,
format: 'esm',
outdir: '../js',
outbase: '../src-js',
});
</code></pre>
<p>html:</p>
<pre><code><script type="importmap">
{
"imports": {
"mylib": "/src-js/my-lib.js"
}
}
</script>
<script type="module" src="/src-js/main.js"></script>
</code></pre>
<p>/src-js/my-lib.js:</p>
<pre><code>export function say_hello() {
alert('hello');
}
</code></pre>
<p>/src-js/main.js:</p>
<pre><code>import { say_hello } from 'mylib';

document.addEventListener("DOMContentLoaded", (e) => {
say_hello();
});
</code></pre>
 

Latest posts

Top