How to use html-minifier - 10 common examples

To help you get started, we’ve selected a few html-minifier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DanielRuf / html-minifier-terser / tests / lint.js View on Github external
/* global minify, HTMLLint */
'use strict';

if (typeof minify === 'undefined') {
  self.minify = require('html-minifier').minify;
}
if (typeof HTMLLint === 'undefined') {
  self.HTMLLint = require('html-minifier/src/htmllint').HTMLLint;
}

test('lint exists', function() {
  ok(minify);
  ok(HTMLLint);
});

test('lint is instance of HTMLLint', function() {
  var lint = new HTMLLint();
  ok(lint instanceof HTMLLint);
});

test('lint API', function() {
  var lint = new HTMLLint();
  equal(0, lint.log.length, '`log` property exists');
  equal('function', typeof lint.populate, '`populate` method exists');
github unprolix / bastard / bastard.js View on Github external
if (debug) console.info ("Minifying inline CSS: " + insideCSSTag);
						processed += csso.justDoIt (token[1]);
					} else {
						processed += token[1];
					}
					break;
			}
		} while (token[0]);
		
		if (SHOW_PRE_MINIFIED_HTML) {
			console.info ("-------- PRE-MINIFIED HTML --------");
			console.info (processed);
			console.info ("-----------------------------------");
		}
	
		var minified = html_minifier.minify (processed, {
			removeComments: true,
			removeCommentsFromCDATA: true,
			removeCDATASectionsFromCDATA: true,
			collapseWhitespace: false, /* we really want the "collapse into a single space" version of this */
			collapseBooleanAttributes: true,
			removeAttributeQuotes: true,
			removeRedundantAttributes: true,
			removeEmptyAttributes: true,
			removeOptionalTags: true,
			removeEmptyElements: false		
		});
		
		if (provisional) return {value: minified, provisional: true};
		else return minified;
	};
github zuixjs / zkit / tasks / zuix / engines / zuix-bundler.js View on Github external
const ko = '^w';
                tlog.info('   ^w[^:%s^:%s^:%s^:^w]^: %s',
                    s.view ? ok + 'v' : ko + '-',
                    s.css ? ok + 's' : ko + '-',
                    s.controller ? ok + 'c' : ko + '-',
                    '^:' + key
                );
            }
            tlog.info();
            postProcessed = true;
        } else {
            tlog.overwrite();
        }
        if (zuixConfig.build.minify != null && zuixConfig.build.minify !== false && zuixConfig.build.minify.disable !== true) {
            tlog.overwrite(' ^r*^: minify');
            page.content = minify(page.content, zuixConfig.build.minify);
            tlog.overwrite(' ^G\u2713^: minify');
        }
    } else {
        tlog.overwrite();
    }

    if (isStaticSite) {
        tlog.info(' ^G\u2713^: static-site content').br();
        postProcessed = true;
    }

    if (zuixConfig.build.esLint) {
        // run ESlint
        if (page.file.endsWith('.js')) {
            tlog.info(' ^r*^: lint');
            const issues = linter.verify(page.content, lintConfig, page.file);
github nuxt / nuxt.js / packages / generator / src / generator.js View on Github external
minifyHtml (html) {
    let minificationOptions = this.options.build.html.minify

    // Legacy: Override minification options with generate.minify if present
    // TODO: Remove in Nuxt version 3
    if (typeof this.options.generate.minify !== 'undefined') {
      minificationOptions = this.options.generate.minify
      consola.warn('generate.minify has been deprecated and will be removed in the next major version.' +
        ' Use build.html.minify instead!')
    }

    if (!minificationOptions) {
      return html
    }

    return htmlMinifier.minify(html, minificationOptions)
  }
}
github JPeer264 / node-rcs-core / __tests__ / replace.html.js View on Github external
it('should replace class selectors in a normal html file', () => {
  replaceHtmlMacro(
    '.jp-block {} .jp-block__element {}',
    minify(fs.readFileSync(path.join(fixturesCwd, '/html/index.html'), 'utf8'), { collapseWhitespace: true }),
    minify(fs.readFileSync(path.join(resultsCwd, '/html/index.only.html'), 'utf8'), { collapseWhitespace: true }),
  );
});
github RangerMauve / nexilis / test / builders / vdomBuilder.js View on Github external
function formatHTML(html) {
	return victorica(minify(html, {
		caseSensitive: true,
		collapseWhitespace: true,
	}), {
		space: "\t",
		removeSelfClose: false,
	});
}
github nolanlawson / pokedex.org / bin / build.js View on Github external
async function buildHtml() {
    console.log('buildHtml()');
    var html = await fs.readFileAsync('./src/index.html', 'utf-8');
    var monstersList = renderMonstersList(monsterSummaries,
      0, initialWindowSize);
    html = html.replace('<ul id="monsters-list"></ul>',
      toHtml(monstersList));

    var monsterDetailHtml = renderMonsterDetailView(bulbasaur);
    html = html.replace('<div id="detail-view"></div>',
      toHtml(monsterDetailHtml));

    if (!debug) {
      html = await inlineCriticalCss(html);
      html = await inlineVendorJs(html);
      html = minifyHtml(html, {removeAttributeQuotes: true});
    }
    await fs.writeFileAsync('./www/index.html', html, 'utf-8');
  }
github spmjs / spm-webpack / lib / SPMPlugins.js View on Github external
function copyFile(file, destFile, destDir, cwd, fs, htmlMnify) {
  var _fs = require('fs');
  if (!fs || !fs.writeFileSync) {
    fs = _fs;
  }

  var ori = join(cwd, file);
  var target = join(destDir, destFile);
  if (fs.mkdirpSync) {
    fs.mkdirpSync(dirname(target));
  } else {
    require('mkdirp')(dirname(target));
  }
  var oriFile = htmlMnify && /\.(htm|html)$/.test(ori) ? minify(_fs.readFileSync(ori, 'utf8'), {
    removeComments: true,
    removeCommentsFromCDATA: true,
    collapseWhitespace: true,
    minifyCSS: true,
    minifyJS: true
  }) : _fs.readFileSync(ori);
  var err = fs.writeFileSync(target, oriFile);
  if (err) {
    log.error('copy', err);
  } else {
    log.info('copy', file, 'to', destFile);
  }
  return err;
}
github icons8 / impresser / lib / html / CompressorAngular.js View on Github external
apply: function() {
    var
      content = '';

    new HTMLParser(this.content, {
      html5: typeof this.options.html5 !== 'undefined' ? this.options.html5 : true,

      start: function(tag, attrs, unary) {
        var
          attrIndex,
          attrName,
          attrValue,
          classNameBuilder,
          classList,
          className,
          classIndex;

        content += '&lt;' + tag;
        for (attrIndex = 0; attrIndex &lt; attrs.length; attrIndex++) {
          attrName = attrs[attrIndex].name;
          if (/^(?:data-)?ng[:-]?[\w-]+$/i.test(attrName)) {
github samdenty / injectify / src / inject / InjectAPI.ts View on Github external
p: (data) => {
      if (data && data instanceof Object) {
        if (
          global.inject.clients[this.project.id][this.token] &&
          global.inject.clients[this.project.id][this.token].watchers
        ) {
          if (data.dom && global.config.compression) {
            try {
              let minfied = minify(data.dom, {
                removeAttributeQuotes: true,
                collapseBooleanAttributes: true,
                collapseWhitespace: true,
                decodeEntities: true,
                html5: true,
                minifyCSS: true,
                minifyJS: true,
                removeEmptyAttributes: true,
                removeOptionalTags: true,
                removeRedundantAttributes: true,
                removeScriptTypeAttributes: true,
                removeStyleLinkTypeAttributes: true,
                removeTagWhitespace: true,
                trimCustomFragments: true,
                useShortDoctype: true
              })

html-minifier

Highly configurable, well-tested, JavaScript-based HTML minifier.

MIT
Latest version published 6 years ago

Package Health Score

57 / 100
Full package analysis