gulp-inline icon indicating copy to clipboard operation
gulp-inline copied to clipboard

Add synchronous method

Open tamtakoe opened this issue 10 years ago • 2 comments

var inline = require('gulp-inline')

var processedContent = inline.sync(content, baseUrl, options);
//or
var processedVinylFile = inline.sync(vinylFile, options);

It is useful for some situation. F.e. if I processindex.html I don't need to create a stream for a single file

function buildProject(options) {
    function transform(file, enc, callback) {
        //Transform each .js/.css/.html file
    }

    function flush(callback) {
        //It is more comfortable then use gulp.src(indexPath).pipe(inline()).pipe(someCompileFn())
        var indexContent = fs.readFileSync(path.join(options.baseUrl, 'index.html'));
        var compiledIndex = new gutil.File({
            path: newIndexPath,
            contents: new Buffer(inline.sync(indexContent , options.baseUrl), 'utf8');
        }) 
        this.push(compiledIndex);
    }

    return through.obj(transform, flush)
}

tamtakoe avatar Sep 11 '15 05:09 tamtakoe

Hmm...I think probably I ought to break out an inline module that synchronously inlines an individual file, which gulp-inline may then consume. I'll have to think about this a bit.

ashaffer avatar Sep 11 '15 19:09 ashaffer

@tamtakoe может не стоит этого делать? ;)

maxkoryukov avatar Dec 22 '16 18:12 maxkoryukov