rollup-plugin-generate-html-template-custom

1.6.5 • Public • Published

rollup-plugin-generate-html-template

build status npm version code coverage

Auto-inject the resulting rollup bundle via a script tag into a HTML template.

Installation

npm install --save-dev rollup-plugin-generate-html-template

Usage

// rollup.config.js
import htmlTemplate from 'rollup-plugin-generate-html-template';
 
export default {
  entry: 'src/index.js',
  dest: 'dist/js/bundle.js',
  plugins: [
    htmlTemplate({
      template: 'src/template.html',
      target: 'index.html',
    }),
  ],
};

On final bundle generation the provided template file will have a script tag injected directly above the closing body tag with a link to the js bundle. By default it uses the same file name and places it directly next to the JS bundle.

<!-- src/index.html -->
<html>
<body>
    <canvas id="main"></canvas>
</body>
</html>
 
<!-- dist/index.html -->
<html>
<body>
    <canvas id="main"></canvas>
    <script src="bundle.js"></script> 
</body>
</html>

Options

  • template: (required) The path to the source template.
  • target: The directory and file name to use for the html file generated with the bundle.
  • attrs: The attributes provided to the generated bundle script tag. Passed as an array of strings Example: attrs: ['async', 'defer] will generate <script async defer src="bundle.js"></script>
  • replaceVars: An object containing variables that will be replaced in the generated html. Example: replaceVars: { '__CDN_URL__': process.env.NODE_ENV === 'production' ? 'https://mycdn.com' : '' } will replace all instances of __CDN_URL__ with http://mycdn.com if the environment is production

License

MIT

Package Sidebar

Install

npm i rollup-plugin-generate-html-template-custom

Weekly Downloads

1

Version

1.6.5

License

MIT

Unpacked Size

167 kB

Total Files

7

Last publish

Collaborators

  • httpsomkar