Consolidate Plugin

Description

Allows importing of templates as a string in your code using the consolidate package.

Install

This plugin depends on the following node modules:

  • consolidate
  • Template engine(s) of your choice, e.g. pug, handlebars etc.

Please check the consolidate documentation for available template engines.

# Using yarn:
yarn add consolidate <template_engine(s)> --dev

# Using npm:
npm install consolidate <template_engine(s)> --save-dev

Usage

Setup

Import from FuseBox

const {ConsolidatePlugin} = require("fuse-box");

Inject into a chain

fuse.plugin(
     ConsolidatePlugin({
       engine: 'pug'
     })
)

Or add it to the main config plugins list to make it available across bundles

FuseBox.init({
    plugins : [
         ConsolidatePlugin({
           engine: 'pug'
         })
    ]
});

Configuration

engine

The engine option is required to tell the ConsolidatePlugin what template engine you want to use. For a list of available engines please refer to the consolidate documentation

extension

If you want to use a different file extension for the ConsolidatePlugin to process then set the extension option. By default the ConsolidatePlugin will use the engine option you provided. For example:

ConsolidatePlugin({ engine: 'pug' }) // will process all files with the extension `.pug` using the `pug` template engine
ConsolidatePlugin({ engine: 'pug', extension: '.custom-extension' }) // will process all files with the extension `.custom-extension` using the `pug` template engine

You can mix and match as you please.

useDefault

useDefault is enable by default. So the transpiled output would look like:

module.exports.default = "<!DOCTYPE html><title>eh</title>";

You can override it and drop back to module.exports by switching to useDefault : false

ConsolidatePlugin({ useDefault : false})

Which will result in:

module.exports = "<!DOCTYPE html><title>eh</title>";

Require file in your code

With useDefault : false

import * as tpl from "./views/file.pug"

With useDefault : true

import  tpl from "./views/file.pug"

Test

To run tests

node test --file=ConsolidatePlugin.test.ts