Created
June 26, 2017 02:59
-
-
Save zhjgithub/5e40ae2e81a17eff6105b882c813e39d to your computer and use it in GitHub Desktop.
From https://stackoverflow.com/questions/23820703/how-to-inject-content-of-css-file-into-html-in-gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(...)); | |
// or for multi files | |
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(...)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment