basham / color-reporter

Analyze and generate HTML report based on CSS color usage.
MIT License
0 stars 0 forks source link

Inline CSS #1

Open basham opened 9 years ago

basham commented 9 years ago

Try to make reports as independent as possible by ensuring there's no external dependencies, such as CSS. Use gulp-replace or gulp-inline-source.

basham commented 9 years ago

From http://stackoverflow.com/a/23834812

var gulp = require('gulp'),
    replace = require('gulp-replace'),
    fs = require('fs');

// in your task
return gulp.src(...)
  .pipe(replace(/<link href="style.css"[^>]*>/, function(s) {
      var style = fs.readFileSync('style.css', 'utf8');
      return '<style>\n' + style + '\n</style>';
  }))
  .pipe(gulp.dest(...));
return gulp.src(...)
  .pipe(replace(/<link href="([^\.]+\.css)"[^>]*>/g, function(s, filename) {
      var style = fs.readFileSync(filename, 'utf8');
      return '<style>\n' + style + '\n</style>';
  }))
  .pipe(gulp.dest(...));