Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var minify = require('html-minifier').minify;
  4. const fs = require('fs');
  5.  
  6. if (!fs.existsSync(dir)){
  7. fs.mkdirSync(dir);
  8. }
  9.  
  10.  
  11. var tagsToReplace = {
  12. '"': '"'
  13. };
  14.  
  15. var htmlFile = fs.readFileSync("testminify.html", "utf8");
  16.  
  17. var result = minify(htmlFile, {
  18. collapseWhitespace: true,
  19. minifyCSS: true,
  20. processConditionalComments: true
  21. });
  22.  
  23. result = addslashes(result)
  24.  
  25. fs.writeFile('minifiedHTML/minified.html', result, (err) => {
  26. // throws an error, you could also catch it here
  27. if (err) throw err;
  28.  
  29. // success case, the file was saved
  30. console.log('HTML file saved!');
  31. });
  32.  
  33. function addslashes( str ) {
  34. return (str + '').replace(/[\"]/g, '\$&').replace(/u0000/g, '\0');
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement