compress.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const { gzip } = require('@gfx/zopfli');
  2. const FS = require('fs');
  3. const path = require('path');
  4. const BUNDLE_JS = FS.readFileSync(path.resolve(__dirname, './dist/js/app.js'));
  5. const HTML = `
  6. <!DOCTYPE html>
  7. <html lang=en>
  8. <head>
  9. <meta charset=utf-8>
  10. <meta http-equiv=X-UA-Compatible content="IE=edge">
  11. <meta name=viewport content="width=device-width,initial-scale=1">
  12. <link rel=icon href=/favicon.ico> <title>ElegantOTA</title>
  13. </head>
  14. <body style="overflow: hidden;">
  15. <noscript>
  16. <strong>We're sorry but ElegantOTA doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
  17. </noscript>
  18. <div id=app></div>
  19. <script defer>${BUNDLE_JS}</script>
  20. </body>
  21. </html>
  22. `;
  23. gzip(HTML, { numiterations: 15 }, (err, output) => {
  24. if (err) {
  25. return console.error(err);
  26. }
  27. const FILE = `
  28. const uint32_t ELEGANT_HTML_SIZE = ${output.length};
  29. const uint8_t ELEGANT_HTML[] PROGMEM = { ${output} };
  30. `;
  31. FS.writeFileSync(path.resolve(__dirname, '../src/elegantWebpage.h'), FILE);
  32. console.log(`[COMPRESS] Compressed Build Files to elegantWebpage.h: ${output.length} Bytes`);
  33. });