gulpfile.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const fs = require('fs');
  2. const gulp = require('gulp');
  3. const htmlmin = require('gulp-htmlmin');
  4. const cleancss = require('gulp-clean-css');
  5. const uglify = require('gulp-uglify');
  6. const gzip = require('gulp-gzip');
  7. const del = require('del');
  8. const inline = require('gulp-inline');
  9. const inlineImages = require('gulp-css-base64');
  10. const favicon = require('gulp-base64-favicon');
  11. const dataFolder = 'build/';
  12. gulp.task('clean', function() {
  13. del([ dataFolder + '*']);
  14. return true;
  15. });
  16. gulp.task('buildfs_embeded', ['buildfs_inline'], function() {
  17. var source = dataFolder + 'index.html.gz';
  18. var destination = dataFolder + 'index.html.gz.h';
  19. var wstream = fs.createWriteStream(destination);
  20. wstream.on('error', function (err) {
  21. console.log(err);
  22. });
  23. var data = fs.readFileSync(source);
  24. wstream.write('#define index_html_gz_len ' + (data.length+1) + '\n');
  25. wstream.write('const char index_html_gz[] PROGMEM = {')
  26. for (i=0; i<data.length; i++) {
  27. wstream.write(data[i].toString());
  28. if (i<data.length-1) wstream.write(',');
  29. }
  30. wstream.write('};')
  31. wstream.end();
  32. del();
  33. });
  34. gulp.task('buildfs_inline', ['clean'], function() {
  35. return gulp.src('src/*.html')
  36. // .pipe(favicon())
  37. .pipe(inline({
  38. base: 'src/',
  39. js: uglify,
  40. css: [cleancss, inlineImages],
  41. disabledTypes: ['svg', 'img']
  42. }))
  43. .pipe(htmlmin({
  44. collapseWhitespace: true,
  45. removeComments: true,
  46. minifyCSS: true,
  47. minifyJS: true
  48. }))
  49. .pipe(gzip())
  50. .pipe(gulp.dest(dataFolder));
  51. })
  52. gulp.task('default', ['buildfs_embeded']);