npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-handlebars-compiler

v0.4.0

Published

Grunt task to precompile Handlebars.js templates with same options as the CLI utility

Downloads

3,789

Readme

grunt-handlebars-compiler

A Grunt plugin for pre-compiling Handlebars templates to a single concatenated file (or individually, whichever floats your boat).

Getting Started

IMPORTANT: This plugin requires Grunt 1.3.0 or higher - it is recommended that you always run the latest version

Install the task:

npm install grunt-handlebars-compiler

Then add this line to your project's Gruntfile.js:

grunt.loadNpmTasks('grunt-handlebars-compiler');

This allows you to use the 'handlebars' task to specify targets!

	handlebars: {
		all: {
			/*
				The output will be formatted as a Common JS module, using a require()
				statement where the argument is the Handlebars path provided in the option.
			*/
			files: {
				'pkg/template-compile-test.js': 'template/*.handlebars'
			},
			options: {
				exportCommonJS: 'handlebars'
			}
		},
		some: {
			/*
				The output will be set to register two templates under 'myApp.templates'
				namespace after stripping the templateRoot:
					* myApp.templates.template1
					* myApp.templates.template2
			*/
			files: {
				'pkg/template-compile-test2.js': [
					'template/webApp-template1.handlebars',
					'template/webApp-template2.handlebars'
				]
			},
			options: {
				namespace: 'myApp.templates',
				templateRoot: 'webApp-',
				knownHelpers: ['if', 'each']
			}
		}
	}

The handlebars task has the following options, none of which are required. The defaults are shown here:

	{
		// specify a character to delimit individual compiled files in the output
		separator: '\n',				
		// specify a namespace for templates to be set to register to
		namespace: 'Handlebars.templates',
		// export compiled templates as AMD (RequireJS) module
		exportAMD: false,				
		// export as Common JS, provide string path to Handlebars instead of false
		exportCommonJS: false,			
		// only relevant if 'exportAMD === true' - provide path to Handlebars
		pathToHandlebars: '',			
		// provide an array of known helpers
		knownHelpers: [],				
		// compile with known helpers only (requires 'knownHelpers')
		knownOnly: false,				
		// a value to strip from the beginning of template names
		templateRoot: false,			
		// EXPERIMENTAL: specify that target templates are partials
		partials: false,					
		// return templates
		returnTemplates: false,			
		// only relevant if 'exportAMD: true' - return the module directly for use
		returnAMD: false
		// uses Handlebars whitespace control to compress HTML (but not Handlebars syntax; you'll have to do that yourself)
		compress: false
		// uses UglifyJS to minify the compiled output
		min: false
	}

Note: You may choose only one 'exportX' option. (Eg. you can't use exportAMD and exportCommonJS on the same task. That would just be straight silly.)

Documentation

The handlebars task is a multi task, meaning that it will implicitly iterate over all of its targets if no target is specified.

Testing

The test suite can be run using grunt test, which uses Nodeunit

Contributing

Feel free to fork if you see possible improvements or contact me directly if you want to contribute to this project (or just submit a pull request): [email protected]

Author

License

This project is licensed under the MIT license.