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

gulp-compile

v1.1.1

Published

Gulp filter for compiling templates into JS source code.

Downloads

5

Readme

gulp-compile

A gulp filter for compiling templates into JS source code. The resulting code may then be wrapped in a module or assigned to a namespace and concatenated.

Another template-compiling Gulp plugin? Why?

Many contributions exist in this area, but I have not been able to find the perfect solution for what I believe is a common AMD build workflow:

  1. Compile template source code into JS source code at build-time (no runtime compilation = faster client code)

  2. Wrap (gulp-wrap-amd) each compiled template in a module for inclusion in, for example, Backbone Views

  3. Optimize (amd-optimize) all AMD modules for a production environment (Almond).

Here are some of the noteworthy similar plugins:

  • gulp-jade: Has support for exactly what I want to do, but only works on ~~Jade~~ Pug templates.

  • gulp-template-compile: Compiles Lo-Dash/Underscore Embedded JavaScript (EJS) templates to JS source, but does not support using templates as modules. Instead, templates are namespaced beneath a global variable (JST by default).

  • gulp-ejs-precompiler: Same issue as gulp-template-compile.

  • gulp-template: Renders EJS templates with data already inserted instead of precompiling them.

  • gulp-ejs: Same issue as gulp-template.

Configuration

options.compiler

A function that accepts a string representation of the template source code as its only argument and returns a function that, when supplied with a context object, produces a rendered template string.

Default: _.template, where _ is Lo-Dash, but resulting templates should be fully compatible with Underscore

options.extension

Compiling to JS is likely the most common use-case for this plugin, but in case the compiler outputs something different (see "Abuses" section below), this option can be used to change the output file's extension.

Default: .js

Abuses

options.compiler can technically return anything: the result of calling toString() is what gets written to the output file. Therefore, if a String-to-String function is passed in, this filter can be used to modify source code or cross-compile just about anything (hence this plugin's generic name). For example, replacing "%VERSION%" with "1.0.0" in all source files. Most web preprocessor languages already have gulp filters (e.g. gulp-jade, gulp-coffee, gulp-less, gulp-sass to name a few): please use them if they work for you! :-)