Home

Awesome

Build Status npm Version License

rollup-plugin-pug-html

Rollup plugin that allows importing pug templates as HTML strings.

Installation

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

Usage

Create the template:

//- template.pug
p Hello #{ name }

Import the template:

// main.js
import html from './template.pug';
console.log(html);  // <p>Hello World</p>

And build with something like...

import { rollup } from 'rollup';
import pug from 'rollup-plugin-pug-html';

rollup({
  entry: 'src/main.js',
  plugins: [
    pug({
      // By default, all .jade and .pug files are compiled
      // extensions: [ '.jade', '.pug' ],
      // You can restrict which files are compiled
      // using `include` and `exclude`
      include: 'src/components/**.pug',
      // You can use native pug options as well.
      pretty: true,
      // You can also pass context for the Pug variables:
      context: { name: 'World' },
    })
  ]
}).then(...)

That's it.

Options

This plugin is using the following pug options as defaults:

{
  doctype: 'html',
  name: 'template',
  compileDebug: false,
  inlineRuntimeFunctions: false,
  context: {},
}

See the full list and explanation in the API Documentation of the Pug site.

Licence

MIT