Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in Gulp to use a string to start with instead of a source file?

Tags:

string

sass

gulp

Normally when I use Gulp I start with:

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

Can I also use a string instead of a file? For example:

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

The use case I'm working on is that I'm creating a SCSS string ad-hoc and want to pipe it to the libsass. But I don't want to have create a temporary file but use a raw string instead. Example:

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

Is this possible?

like image 808
Giel Berkers Avatar asked Nov 01 '22 03:11

Giel Berkers


1 Answers

You may 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'));
});
like image 169
demisx Avatar answered Nov 09 '22 12:11

demisx