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-inject-html

v1.0.5

Published

inject the content of a html dependence into AMD module as a variable

Downloads

2

Readme

gulp-inject-html

Assuming your AMD module depends on a html file(load with textjs), and you want pack the module and the html together, then this is what are you looking for!

gulp-inject-html will go through your code and figure out the html dependences, and then inject the html content into your module as a variable!

for more information, see Usage section below.

Install

$ npm install --save-dev gulp-inject-html

Usage

prepare your files
  • templates
    • index.html
  • views
    • index.js
  • data-main.js
prepare your code

if you use a path-builder just as i do as below, then you need to provide "templates" which is the folder that holds your html templates for gulp-inject-html. gulp-inject-html will lookup respective html file and inject it into your module.

And if your path-builder is different from mine, you may need to tell gulp-inject-html what it looks like via "pathBuilder"(array for muti, or string for single one).

/***
 * js in data-main js
 **/
window._buildTextPath = function( fileName ){
	return "text!../templates/" + fileName );
}

/***
 * views/index.js
 **/
define(['base', _buildTextPath( 'index.html' ), 'vote'], function( Baseview, Html, Vote ){
	"use strict";
	......
})

or you just use your "text" plugin without any decoration like the following, then you need provide "baseUrl" (an option for requirejs) for gulp-inject-html, gulp-inject-html will lookup respective html file relatively.

define(['base', 'text!../templates/index.html', 'vote'], function( Baseview, Html, Vote ){
	"use strict";
	......
})
/***
 * template/index.html
 **/
<div class="index-fixedbtn" v-attr="event-url:signuped?'mywork':'signup'"></div>
<div class="index-t ac">
    <button class="btn redbtn" event-src="voteTa">给她投票</button><br>
    <i></i>
</div>

prepare your gulp task

/***
 * in gulpfile.js
 **/
var injecthtml  = require('gulp-inject-html');
...

gulp.task( 'build', function(){
	return gulp.src( './views/*.js' ) )
	    .pipe( injecthtml({ 
	    	templates: 'templates',
	    	baseUrl: 'views',
	    	pathBuilder: [ '_buildTextPath', '_buildTextPath2' ]
	    })) 
	    .pipe( gulp.dest( './buld/views' ));
})


// templates: the folder that hold your html templates. 
// gulp-inject-html will read the html file that has the same name as your module's.
build result
/***
 * build/views/index.js
 **/
 
define(['base', 'vote' ], function (Baseview, Vote) {
    'use strict';
    var Html = '<div class="index-fixedbtn" v-attr="event-url:signuped?\'mywork\':\'signup\'"></div>\r\n<div class="index-t ac">\r\n    <button class="btn redbtn" event-src="voteTa">给她投票</button><br>\r\n    <i></i>\r\n</div>';
    
    ...

options

templates

Type: string. Refer to Usage section.

baseUrl

Type: string. Refer refer to Usage section.

pathBuilder

Type: string or array. Refer to Usage section.

htmlClean

Type: object

gulp-inject-html use htmlclean to handle your html template. htmlClean is the options for htmlclean.

Note

  • DO NOT put code before define([],function(){}) call
  • your html template file MUST has the same name as your module's