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

v0.0.14

Published

Find assets in HTML file, revisioning assets, rewrite references in each file

Downloads

50

Readme

gulp-html-assets

NPM

Find assets in HTML file, revisioning assets, rewrite references in each file.

Install

Install with npm

npm install --save-dev gulp-html-assets

Usage

Source html:

<div>
<link rel="stylesheet" href="./index.entry.css">
<img src="./images/red-tree-2.jpg" alt="Red Tree" />
<script src="./index.entry.js"></script>
</div>

Gulp:

var gulp = require('gulp');
var gulpHTMLAssets = require('gulp-html-assets');
var path = require('path');

const DEBUG = process.env.NODE_ENV !== 'production';
const OUTPUT_PATH = path.resolve('../output');

var manifest = {};

gulp.task('default', function () {
    var stream = gulp.src(['**/*.html'])
        .pipe(gulpHTMLAssets({
            root: path.resolve('.'),
            dest: OUTPUT_PATH,
            file: '[name]' + (DEBUG ? '' : '-[hash]') + '.[ext]',
            prefix: '/assets/build/',
            indexes: manifest
        }))
        .pipe(gulp.dest(OUTPUT_PATH));
        
    stream.on('end', function () {
        fs.writeFileSync(OUTPUT_PATH + '/manifest.json', JSON.stringify(manifest, null, 2));
    });
    
    return stream;
});

Output:

<div>
<link rel="stylesheet" href="/assets/build/index.entry-472ce2cca6184c821e7804b855ac216c.css">
<img src="/assets/build/images/red-tree-2-68add0b5d16c3317de6cd16693269d4c.jpg" alt="Red Tree" />
<script src="/assets/build/index.entry-eae2b4beaf92fc30a996de142be88f97.js"></script>
</div>

Output manifest file:

{
  "index.entry.css": "index.entry-472ce2cca6184c821e7804b855ac216c.css",
  "index.entry.js": "index.entry-eae2b4beaf92fc30a996de142be88f97.js",
  "images/red-tree-2.jpg": "images/red-tree-2-68add0b5d16c3317de6cd16693269d4c.jpg"
}

Options

.pipe(gulpHTMLAssets({ options })

root

Type: String

Set the assets root path

dest

Type: String

Set the assets target path

file

Type: String

Set the assets target file name, support [name], [hash], [ext] placeholder.

Example:

file: '[name].[ext]'

With hash:

file: '[name]-[hash].[ext]'

Condition hash:

file: '[name]' + (DEBUG ? '' : '-[hash]') + '.[ext]'

prefix

Type: String

Set the assets references prefix in HTML.

HTML:

<script src="./index.entry.js"></script>

Output:

<script src="/assets/build/index.entry.js"></script>

Output with CDN:

<script src="http://c.d.n/assets/build/index.entry.js"></script>

template

Type: String

HTML reference template, it's useful when work with backend templates.

Support [key], [value] and [uri] placeholder, [key] is the indexes key, [value] is the indexes value, [uri] is the full uri.

Config:

{
    template: "{{ assets \"[key]\" }}"
}

HTML:

<div>
<link rel="stylesheet" href="./index.entry.css">
</div>

Output:

<div>
<link rel="stylesheet" href="{{ assets "index.entry.css" }}">
</div>

indexes

Type: Object{}

Assets source and target map references.

exts

Type: Object

Convert exts from source to target, references will be effected.

Config:

{
    prefix: "/assets/build/",
    exts: {
        '.ts': '.js',
        '.scss': '.js'
    }
}

HTML:

<div>
<link rel="stylesheet" href="./index.entry.scss">
</div>

Output:

<div>
<link rel="stylesheet" href="/assets/build/index.entry.css">
</div>