Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-html-compile

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-html-compile

A small gulp plugin to compile your static html into javascript templates

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

gulp-html-compile

Compile static ( no logic ) HTML templates into javascript files

Synopsis

This plugin is heavily inspired by Emanuele Ingrosso's gulp plugin which was itself inspired by Sindre Sorhus's gulp-nunjucks plugin.

Install

Install with npm

npm install gulp-html-compile --save-dev

Example

template

<h1 class="my-header">Welcome to my awesome site!</h1>

gulpfile

var gulp = require( 'gulp' ),
    template = require( 'gulp-html-compile' ),
    concat = require( 'gulp-concat' ),
    wrap = require( 'gulp-wrap' );

gulp.task( 'templates', function() {
    gulp.src( './templates/**/*.html' )
        .pipe( template({
            name: function( file ) {
                return file.relative.split( '.' )[ 0 ];
            },
            namespace: 'myTemplates'
        }))
        .pipe( concat( 'myTemplates.js' ))
        .pipe( wrap( 'module.exports = window["myTemplates"]'))
        .pipe( gulp.dest( './js/'));
});

API

template( options )

options

Type: object

options.name

Type: string Default: Relative template path Example: templates/header.html

You can override the default behavior by supplying a function which gets the current File object and is expected to return the name.

{
    name: function( file ) {
        return file.relative.split( '.' )[ 0 ];
    }
}
options.namespace

Type: 'string' Default: 'templates'

The namespace in which the precompiled templates will be assigned.

{
    namespace: 'MyCoolTemplates'
}

License

MIT

Keywords

FAQs

Package last updated on 13 Oct 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc