plugin-html/README.md
Miel Truyen ba07649981
Some checks failed
continuous-integration/drone/push Build is failing
0.0.2: Updated docs to reflect current state
2023-05-02 15:47:23 +02:00

5.8 KiB

npm size libera manifesto

rollup-plugin-html-entry2

⚠️ WARNING
Experimental-stage plugin. Expect bugs and missing features...

A(nother) rollup plugin that tries to teach Rollup to start from an HTML entry, and the use of (multiple) HTML files in general. The goal is to include assets referenced by the HTML file into the build-process as to copy/inline where appropriate and optionally optimize them. Without having to seperatly copy them to the output directory.

When building web-applications a HTML-file is simply the logical entry point into your application.
Inspired (and forked) by the original @rollup/plugin-html, this plugin will also allow you to transform the source files by any HTML-templating engine such as handlebars.

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

Requirements

This plugin requires an LTS Node version (v18.0.0+) and Rollup v3.?.?+.

Install

Using npm:

npm install rollup-plugin-html-entry2 --save-dev

Usage

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

import html from 'rollup-plugin-html-entry2';

export default {
  input: 'src/index.html',
  output: {
    dir: 'output',
  },
  plugins: [html()]
};

!! To use 'import x from y' syntax you might need to set "type": "module" in your package.json. Javascript modules are the preferred way of writing modern Javascript. Due to the early stage development of this plugin, old-style CommonJS modules are completely ignored for now.

Then call rollup either via the CLI or the API.

Options

template

Type: Function
Default: undefined
Returns: String

Specifies a transform to be applied before parsing the HTML, this allows you to transform the sourcefile with a templating engine such as handlebars first.

import {rollup} from "rollup";
import handlebars from "handlebars";
import html from "rollup-plugin-html-entry2";

async function build() {
    await rollup({
        input: 'index.hbs',
        plugins: [
            html({
                transform(src) {
                    return handlebars.compile(src)({a: 'a'})
                }
            })
        ]
    });
}

Supported Output Formats

By default, this plugin supports the esm (es). Any other format is currently untested as this plugin is in an early state, see #status

Status

This plugin is in an early state. As such not everything that is supported yet, the options are laregely undocumented and may change.

(Rudimentarily) supported

  • Importing JS via <script src="..." type="module"> tags
  • Importing assets using @rollup/plugin-url (which could use an update TBH)
  • Compatibility with other plugins such as @rollup/plugin-node-resolve, @rollup/plugin-babel, @rollup/plugin-commonjs, @rollup/plugin-terser and rollup-plugin-livereload
  • Inline scripts (i.e <script>...</script>)

Not (yet/properly) supported

  • Plugins importing CSS files
  • CommonJS (cjs) and IIFI output formats. (Is UMD actually ever used?)
  • Overriding which DOM-nodes and resulting URLS to ignore/include (in a clean way)
  • Other (various) plugins such as typescript, or those for HMR etc
  • ...

Contibuting

You can be helpful by testing, proving helpful feedback, expanding the documentation, responding to issues/questions being reported, resolving the many ToDo`s in the code, implementating features...
Get in touch or just dive into the code or issues.

See also the ToDo-list at the end of the changelog

Notes

git.cerxes.net

Once publicly released, the intent is to move the GIT-repository to github. Until that day though, it exists privately on this gitea server and corresponding npm-registry npm.cerxes.net.
TODO: change the links once this happens

Prior work