Is it possible in Gulp to use a line to start instead of the source file?

Usually when I use Gulp, I start with:

gulp.src('some/file.txt).pipe( ... ) // etc

Is it possible to use a string instead of a file? For instance:

gulp.str('some text').pipe( .... ) // etc

The use case I'm working on is that I create an ad-hoc SCSS string and want to pass it to libsass. But I do not want to create a temporary file, but instead I use an unprocessed string. Example:

var myString = 'html { color: red; }';
gulp.str(myString).pipe(sass()) // etc

Is it possible?

+4
source share
1 answer

You can try something like this:

var file = require('gulp-file');

gulp.task('build', function () {
  var str = 'Some string value that you want to pipe';

  return file('tmp.js', str, { src: true }) // The file name can be anything
    ... // <- Piping contents of str here
    .pipe(gulp.dest('xxx'));
});
+1
source

All Articles