I have the following sass
task which compiles app.scss
to app.css
and reloads the page:
gulp.task('sass', function() {
return gulp.src('./app/app.scss')
.pipe(sass())
.pipe(gulp.dest('./app'))
.pipe(livereload());
});
Now, I want to compile another file, namely ui-toolkit.scss
to ui-toolkit.css
.
Is this the best way to update the task?
gulp.task('sass', function() {
gulp.src('./ui-toolkit/ui-toolkit.scss')
.pipe(sass())
.pipe(gulp.dest('./ui-toolkit'));
return gulp.src('./app/app.scss')
.pipe(sass())
.pipe(gulp.dest('./app'))
.pipe(livereload());
});
Setting up a task Still using the command line, you can install Gulp-sass by running npm install gulp-sass --save-dev . After that, require Gulp-sass in your gulpfile. js. Put var sass = require('gulp-sass'); under the line you required gulp.
Gulp is a tool that helps you out with several tasks when it comes to web development. It's often used to do front end tasks like: Spinning up a web server. Reloading the browser automatically whenever a file is saved. Using preprocessors like Sass or LESS.
The src() and dest() methods are exposed by gulp to interact with files on your computer. src() is given a glob to read from the file system and produces a Node stream. It locates all matching files and reads them into memory to pass through the stream.
Just specify glob(s) that match multiple scss files. These examples assume you want to save the results to same directory as the source file.
Matches every scss file (in node_modules too):
gulp.task('sass', function() {
return gulp.src('./**/*.scss')
.pipe(sass())
.pipe(gulp.dest('.'));
});
Matches scss files in specific dirs:
gulp.task('sass', function() {
return gulp.src('./{foo,bar}/*.scss')
.pipe(sass())
.pipe(gulp.dest('.'));
});
Matches only specific files (base option is needed here for saving to same directory as source file):
gulp.task('sass', function() {
return gulp.src(['./foo/foo.scss', './bar/bar.scss'], { base: '.' })
.pipe(sass())
.pipe(gulp.dest('.'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With