Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-html-plugin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-html-plugin

An esbuild plugin that generates an HTML file.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

esbuild-html-plugin

An esbuild plugin that generates an HTML file.

This esbuild plugin allows the creation of an HTML file featuring output URLs of bundled assets, while supporting customization of head and body elements. The esbuild's minify option handles minification.

Installation

npm install esbuild-html-plugin

Usage Example

import * as esbuild from 'esbuild';

await esbuild.build({
  entryPoints: [`app.ts`],
  bundle: true,
  minify: true,
  outdir: `dist`,
  publicPath: `/static`,
  plugins: [
    htmlPlugin({
      outfile: `index.html`,

      createHeadElements: () => [
        `<meta charset="utf-8" />`,
        `<meta name="viewport" content="width=device-width, initial-scale=1" />`,
        `<title>Example</title>`,
      ],

      createBodyElements: (outputUrls) =>
        outputUrls
          .filter((outputUrl) => outputUrl.endsWith(`.js`))
          .map((outputUrl) => `<script src="${outputUrl}"></script>`),
    }),
  ],
});

Options

outfile (required)

The output file's name for the generated HTML. This name will be combined with the outdir or the dirname of the outfile from the esbuild options.

{
  outfile: `index.html`,
}

language (optional)

The language attribute for the HTML tag.

{
  language: `en`,
}

createHeadElements (optional)

A function that receives the output URLs of the bundled assets and returns an array of strings representing the custom head elements.

{
  createHeadElements: (outputUrls) =>
    outputUrls
      .filter((outputUrl) => outputUrl.endsWith(`.css`))
      .map((outputUrl) => `<link rel="stylesheet" href="${outputUrl}">`),
}

createBodyElements (optional)

A function that receives the output URLs of the bundled assets and returns an array of strings representing the custom body elements.

{
  createBodyElements: (outputUrls) =>
    outputUrls
      .filter((outputUrl) => outputUrl.endsWith(`.js`))
      .map((outputUrl) => `<script src="${outputUrl}"></script>`),
}

FAQs

Package last updated on 12 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc