npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rollup/plugin-html

v1.0.4

Published

Creates HTML files to serve Rollup bundles

Downloads

72,717

Readme

npm size libera manifesto

@rollup/plugin-html

🍣 A Rollup plugin which creates HTML files to serve Rollup bundles.

Please see Supported Output Formats for information about using this plugin with output formats other than esm (es), iife, and umd.

Requirements

This plugin requires an LTS Node version (v14.0.0+) and Rollup v1.20.0+.

Install

Using npm:

npm install @rollup/plugin-html --save-dev

Usage

Create a rollup.config.js configuration file and import the plugin:

const html = require('@rollup/plugin-html');

module.exports = {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [html()]
};

Then call rollup either via the CLI or the API.

Once run successfully, an HTML file should be written to the bundle output destination.

Options

attributes

Type: Object Default: { html: { lang: 'en' }, link: null, script: null }

Specifies additional attributes for html, link, and script elements. For each property, provide an object with key-value pairs that represent an HTML element attribute name and value. By default, the html element is rendered with an attribute of lang="en".

Note: If using the es / esm output format, { type: 'module'} is automatically added to attributes.script.

fileName

Type: String Default: 'index.html'

meta

Type: Array[...object] Default: [{ charset: 'utf-8' }]

Specifies attributes used to create <meta> elements. For each array item, provide an object with key-value pairs that represent <meta> element attribute names and values.

Specifies the name of the HTML to emit.

publicPath

Type: String Default: ''

Specifies a path to prepend to all bundle assets (files) in the HTML output.

template

Type: Function Default: internal function Returns: String

Specifies a function that provides the rendered source for the HTML output. The function should be in the form of:

const template = ({ attributes, bundle, files, publicPath, title }) => { ... }
  • attributes: Corresponds to the attributes option passed to the plugin
  • bundle: An Object containing key-value pairs of AssetInfo or ChunkInfo
  • files: An Array of AssetInfo or ChunkInfo containing any entry (isEntry: true) files, and any asset (isAsset: true) files in the bundle that will be emitted
  • publicPath: Corresponds to the publicPath option passed to the plugin
  • title: Corresponds to the title option passed to the plugin

By default this is handled internally and produces HTML in the following format:

<!DOCTYPE html>
<html ${attributes}>
  <head>
    ${metas}
    <title>${title}</title>
    ${links}
  </head>
  <body>
    ${scripts}
  </body>
</html>

Where ${links} represents all <link .. tags for CSS and ${scripts} represents all <script... tags for JavaScript files.

title

Type: String Default: 'Rollup Bundle'

Specifies the HTML document title.

Exports

makeHtmlAttributes(attributes)

Parameters: attributes, Type: Object Returns: String

Consumes an object with key-value pairs that represent an HTML element attribute name and value. The function returns all pairs as a space-separated string of valid HTML element attributes. e.g.

const { makeHtmlAttributes } = require('@rollup/plugin-html');

makeHtmlAttributes({ lang: 'en', 'data-batcave': 'secret' });
// -> 'lang="en" data-batcave="secret"'

Supported Output Formats

By default, this plugin supports the esm (es), iife, and umd output formats, as those are most commonly used as browser bundles. Other formats can be used, but will require using the template option to specify a custom template function which renders the unique requirements of other formats.

amd

Will likely require use of RequireJS semantics, which allows only for a single entry <script> tag. If more entry chunks are emitted, these need to be loaded via a proxy file. RequireJS would also need to be a dependency and added to the build: https://requirejs.org/docs/start.html.

system

Would require a separate <script> tag first that adds the s.js minimal loader. Loading modules might then resemble: <script>System.import('./batman.js')</script>.

Attribution

This plugin was inspired by and is based upon mini-html-webpack-plugin by Juho Vepsäläinen and Artem Sapegin, with permission.

Meta

CONTRIBUTING

LICENSE (MIT)