How to use the html-minifier.minify function in html-minifier

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 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 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
              })
github majgis / ngify / lib / NgifyHtmlStreamReader.js View on Github external
NgifyHtmlStreamReader.prototype._getOutput = function () {
    var settings = this._settings;
    var html = minify(
        this._chunks.join('').replace(/\r?\n|\r/g, " "),
        settings.getValue('htmlMinifyArgs')
    );

    var htmlName = settings.getValue('htmlName');

    return format(
        settings.getValue('moduleTemplate') +
        settings.getValue('htmlTemplate'),
        {
            html: html.replace(/'/g, "\\'"),
            moduleName: settings.getValue('moduleName'),
            htmlName: htmlName
        }
    ) + "\nmodule.exports = '" + htmlName + "';";
};
github astronomersiva / lego / lib / utils / minifyHtml.js View on Github external
const findUp = require('find-up');
    const { minify } = require('html-minifier');

    let configFile = findUp.sync('lego.js');
    let config = {
      collapseWhitespace: true,
      minifyJS: true,
      minifyCSS: true,
      removeComments: true
    };

    if (configFile) {
      config = Object.assign(config, require(configFile).htmlMinifier);
    }

    return minify(html, config);
  } catch (error) {
    throw error;
  }
}

html-minifier

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

MIT
Latest version published 6 years ago

Package Health Score

59 / 100
Full package analysis