本文整理汇总了TypeScript中html-minifier.minify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript minify函数的具体用法?TypeScript minify怎么用?TypeScript minify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了minify函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: minify
return es.map(function(file: any, callback: (err: any, htmlMinifierfile: any) => void) {
var template = '$templateCache.put("<%= url %>","<%= contents %>");';
var url;
file.path = path.normalize(file.path);
if(typeof options.path === 'function') {
url = path.join(options.path(file.path, file.base));
} else {
url = path.join(file.path);
url = url.replace(file.base, '');
};
if (process.platform === 'win32') {
url = url.replace(/\\/g, '/');
}
let contents = file.contents.toString();
if(options.htmlMinifier) {
contents = minify(contents, options.htmlMinifier);
}
contents = require('js-string-escape')(contents);
file.contents = Buffer.from(lodashTemplate(template)({
url: url,
contents: contents,
file: file
}), 'utf8');
callback(null, file);
});
示例2: minifyHtml
global['collapseSpacesReplacement'] = (html: string) => {
return minifyHtml(html, {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
keepClosingSlash: true
}).replace(/\t/g, '');
};
示例3: minifyHtml
export function minifyHtml(html: string) {
return htmlMinify(html, {
removeComments: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true
});
}
示例4: minify
export function minify(html: string): string {
return htmlMinifier.minify(html, {
caseSensitive: true,
collapseWhitespace: true,
conservativeCollapse: true,
minifyCSS: true,
minifyJS: true,
processScripts: ['text/template'],
removeComments: true,
});
};
示例5: minifyHtml
export function minifyHtml(html: string) {
const options: htmlMinifier.Options = {
caseSensitive: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
};
return htmlMinifier.minify(html, options);
}
示例6: minify
export function minify(html: string): string {
// Just parse the html to make sure it is correct before minifying
HTMLTools.parseFragment(html);
return htmlMinifier.minify(html, {
collapseWhitespace: true,
conservativeCollapse: true,
minifyCSS: true,
minifyJS: true,
processScripts: ['text/template'],
});
};
示例7: minify
export function minify(html: string): string {
return htmlMinifier.minify(html, {
collapseWhitespace: true,
conservativeCollapse: true,
minifyCSS: true,
minifyJS: true,
processScripts: ['text/template'],
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [ [/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/] ],
customAttrAssign: [ /\)?\]?=/ ],
});
};
示例8: catch
options.renderer.render(options.indexFilename, config, (err, html) => {
if (err) {
console.log(err);
return;
}
try {
fs.accessSync(options.targetPath);
} catch (e) {
fs.mkdirSync(options.targetPath);
}
console.log(html);
const minifiedHtml = minify(html, {
minifyCSS: true,
minifyJS: true,
removeComments: true,
collapseWhitespace: true
});
// console.log(minifiedHtml);
fs.writeFileSync(options.targetPath + '/index.html', minifiedHtml);
});
示例9: minify_html
export default function minify_html(html: string) {
return minify(html, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
html5: true,
ignoreCustomComments: [/^#/],
minifyCSS: true,
minifyJS: false,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true
});
}
示例10: function
start: function (resource, options, gOptions, wp) {
var opt = options;
var isDebug = gOptions.debug;
if (!isDebug) {
var html = resource.value('string');
resource.set('string', htmlmin(html, opt));
}
}