Preprocess static HTML files in Brunch with plain JS.

Usage no npm install needed!

<script type="module">
  import brunchPreval from '';



brunch-preval v0.0.3

Simple JS based preprocessing for Brunch static HTML files.

seanmorris-brunch-preval Size badge


$ npm i brunch-preval


Simply open a static HTML file and put some javascript inside {{ double curly braces }}. The javascript will be evaluated, and the results will be interpolated in its place.

<html><body>{{ Math.random() }}</body></html>


Use the backslash (\) character to escape a replacement

<html><body>\{{ This won't be processed. }}</body></html>

Escaping Escapes

Backslashes may also be used to escape a backslash.

    {{ "This WILL be processed." }}
    \{{ "This won't be processed."" }}
    \\{{ "This WILL be processed and will be preceeded by a single backslash." }}
    \\\{{ "This won't be processed and will be preceeded by a single backslash." }}
    \\\\{{ "This WILL be processed and will be preceeded by a 2 backslashes." }}

Alt Notation

<<< triple angle brackets >>> or ((( triple parens ))) may also be used.


See also configuring Brunch


You can more finely control which HTML files are processed by specifying a regex for the include & exclude keys.

If a file matches both include and exclude the include will take precedence.

exports.plugins = {
        exclude: /thing.html$/,
        , include: /something.html$/,


Tokens can be specified in your Brunch config.

Tokens may be static values or the results of a function. Dynamic tokens will be generated once per compile pass, and will have the same value for all files processed in each pass.

Tokens in templates can be accessed on the _ object.

<html><body>{{ _.BUILD_TIME }}</body></html>
exports.plugins = {
        tokens: {
            STATIC_VAL: 'Some value',
            BUILD_TIME: ()=>(new Date).getTime() / 1000,

Suppress Logging

Set log to false in your Brunch config to stop BrunchPreval from logging to the console during compilation.

exports.plugins = {
        log: false