Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var minify = require('html-minifier').minify;
- const fs = require('fs');
- if (!fs.existsSync(dir)){
- fs.mkdirSync(dir);
- }
- var tagsToReplace = {
- '"': '"'
- };
- var htmlFile = fs.readFileSync("testminify.html", "utf8");
- var result = minify(htmlFile, {
- collapseWhitespace: true,
- minifyCSS: true,
- processConditionalComments: true
- });
- result = addslashes(result)
- fs.writeFile('minifiedHTML/minified.html', result, (err) => {
- // throws an error, you could also catch it here
- if (err) throw err;
- // success case, the file was saved
- console.log('HTML file saved!');
- });
- function addslashes( str ) {
- return (str + '').replace(/[\"]/g, '\$&').replace(/u0000/g, '\0');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement