rollup-plugin-html-entry

0.3.0 • Public • Published

Build Status

rollup-plugin-html-entry

Use HTML files as entry points in your rollup bundle. HTML files and HTML imports will be traversed, then all scripts found will be combined. Optionally, write HTML files cleaned of <script>s. This is particularly useful for web components and web applications in general.

<!-- 0.html -->
<script>export const zero = 0;</script> 
<!-- 1.html -->
<script>export const one = 1;</script> 
<!-- 2.html -->
<script src="2.js"></script>
// 2.js
export const two = 2;
<!-- all-imports.html -->
<link rel="import" href="0.html">
<link rel="import" href="1.html">
<link rel="import" href="2.html">
 

Using all-imports.html as entry point will yield a bundle with exports for zero, one, and two.

So, this plugin works like rollup-plugin-multi-entry does, but using <script>s contained in HTML files as entry points.

Install

$ npm install [--save-dev] rollup-plugin-html-entry

Usage

This plugin requires at least v0.48.0 of rollup. In rollup.config.js:

import htmlEntry from 'rollup-plugin-html-entry';
 
export default {
  input: 'test/**/*.html',
  plugins: [htmlEntry()]
};

The input above is the simplest form which simply takes a glob string. You may pass an array of glob strings or an object with one or more of the following options:

export default {
  input: {
    // Arrays of globs to include
    include: ['index.html', 'and/globs/**/*.html'],
    // Arrays of globs to exclude
    exclude: ['excluded-file.html', 'and/globs/*.to.be.excluded.html'],
    // Arrays of globs that should remain external to the bundle
    external: ['lazy-imports.html', 'and/globs/*.to.be.omitted.html']
  }
  // ...
};
 

By default HTML files will be not written. If output option is present, HTML files stripped of <script>s will be written into specified path.

export default {
  input: 'index.html',
  plugins: [htmlEntry({ output: "build" })]
  // ...
};

Finally, you may not need to export anything from the rolled-up bundle for web applications. In such cases, use the exports: false option like so:

export default {
  input: 'index.html',
  plugins: [htmlEntry({ exports: false })]
};

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i rollup-plugin-html-entry

Weekly Downloads

7

Version

0.3.0

License

MIT

Unpacked Size

20.1 kB

Total Files

6

Last publish

Collaborators

  • leogr