New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-minify-tag

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-minify-tag

You can use this code to minify your css and js code between begin and end comment tags in a given html file.

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

minify-tag

Minifier of js, css, html.

It is a wrapper for the gorgeous node-minify.

You can use it programmatic as script or as CLI.

Advantage / Motivation: Instead of separate mapping files and html code the needed informations can be set with help of html comments:

<html>
<head>
    <!-- node-minify-tag-glob( {"htmlOut": "_index1.prod.html"} ) -->
    ...
    <title>index1</title>
    ...
    <!-- node-minify-tag( {"fileOut":"_abc1.min.css", "type": "no-compress"} ) -->
    <link href="css/base.css" rel="stylesheet">
    <link href="css/base2.css" rel="stylesheet">
    <!-- node-minify-tag-end -->
</head>
<body>
...
<!-- node-minify-tag( {"fileOut":"_abc.min.js", "type": "no-compress"} ) -->
    <script src="js/jquery-2.0.3.js"></script>
    <script src="js/base.js"></script>
    <script src="js/base2.js"></script>
<!-- node-minify-tag-end -->
...

Usage

As script :

var minifyTag = require('node-minify-tag');

// HTML in and out file are explicitly specified: 
// No need for 'node-minify-tag-glob' tag:
minifyTag.minify({
        relativeBaseDir: "demo",
        htmlIn: "abc.dev.html",
        htmlOut: "__abc.prod.html",
        encoding: "utf8",
        mergeNgIncludes: true
    }, 
    function (err, msg){
        if (err) return reject(err);
        resolve(msg);
    });


// Glob mode: 
// minifyByGlob walk through the sub directories 
// and looks for all file matching 'filePattern'.
// The 'htmlOut' file for each 'htmlIn' must be specified 
// in an 'node-minify-tag-glob' comment tag
minifyTag.minifyByGlob({
        relativeBaseDir: "../../Xy/",
        filePattern: "**/*.dev.html",
        encoding: "utf8",
        mergeNgIncludes: true
    }, 
    function (err, msg){
        if (err) return reject(err);
        resolve(msg);
    });

HTML comment attributes

Comment tagCorresponding comment tagOptions
node-minify-tag( options )node-minify-tag-endsee below
node-minify-tag-glob( options )none{"htmlOut": "sample.prod.html"}

Options node-minify-tag

KeyPossible valuesActionFile type
type'no-compress'concatenation of filesJS / CSS
type'gcc'Google Closure CompilerJS
type'yui-js'YUI CompressorJS
type'yui-css'YUI CompressorCSS
type'uglifyjs'UglifyJSJS
type'sqwish'SqwishCSS
type'clean-css'Clean-cssCSS
type'csso'CSSOCSS
fileOut name of generated (compressed) html or CSS file--

Options node-minify-tag-glob

KeyPossible valuesExample
htmlOut name of generated html file'index.prod.html'

As CLI

node node_modules/node-minify-tag/index.js -h

// Explicit mode:
node node_modules/node-minify-tag/index.js -d test/demo/ -i abc.html -o __abc.prod.html 

// glob mode:
node node_modules/node-minify-tag/index.js -g -d test/demo/ -p **/*.dev.html

Information about glob file pattern can be found here: Glob Primer.

Keywords

Javascript minifier

FAQs

Package last updated on 07 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