Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

brunch-preval

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brunch-preval

Preprocess static HTML files in Brunch with plain JS.

latest
npmnpm
Version
0.0.4-a
Version published
Maintainers
1
Created
Source

avatar

brunch-preval v0.0.3

Simple JS based preprocessing for Brunch static HTML files.

seanmorris-brunch-preval Size badge

Install

$ npm i brunch-preval

Use

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>

Escaping

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.

<html>
<body>
	{{ "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." }}
</body>
</html>

Alt Notation

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

Configure

See also configuring Brunch

Include/exclude

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 = {
	preval:{
		exclude: /thing.html$/,
		, include: /something.html$/,
	}
};

Tokens

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 = {
	preval:{
		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 = {
	preval:{
		log: false
	}
};

FAQs

Package last updated on 23 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts