@esbuilder/html

Plugin that simplifies creation of HTML files to serve your esbuild bundles.

Usage no npm install needed!

<script type="module">
  import esbuilderHtml from 'https://cdn.skypack.dev/@esbuilder/html';
</script>

README

esbuild HTML Plugin

Plugin that simplifies creation of HTML files to serve your esbuild bundles.

TOC

Usage

Install

# yarn
yarn add -D esbuild @esbuilder/html

# npm
npm install -D esbuild @esbuilder/html

API

import esbuild from 'esbuild'
import { html } from '@esbuilder/html'

// serve mode
await esbuild.serve(
  {},
  {
    entryPoints: ['src/index.html'],
    plugins: [
      html({
        // required in serve mode
        serve: true,
        /**
         * Output filename pattern for `src` attribute in `script` tag,
         * the default value is `[name].[hash]`,
         * you can override it here.
         */
        // entryNames: 'js/[name]',
      }),
    ],
    outdir: 'dist',
    /**
     * required for keeping `dist/index.html` instead of `dist/index.{hash}.html`
     */
    assetNames: ['[name]'],
  },
)

// build mode
await esbuild.build({
  entryPoints: ['src/index.html'],
  plugins: [html()],
  outdir: 'dist',
  assetNames: ['[name]'],
})
<!-- src/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <!-- ... -->
  </head>
  <body>
    <script src="index.ts"></script>
  </body>
</html>

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me