U
U
udzumaki2019-05-19 20:06:55
gulp.js
udzumaki, 2019-05-19 20:06:55

Can't autocompile sass?

Hello toasters. Help with a problem.
You need sass to compile to css. Here is my code.
5ce18c04cd35a839568320.png
I know that you can use asterisks, but for clarity, I replaced everything with main.scss. But it is not important. Well, now I go to cmd, write a command and an error pops up.
5ce18cfee9d36123943801.png
Nothing compiles. Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery, 2019-05-19
@udzumaki

Try like this:

// Include gulp
var gulp = require('gulp');

// Include Plugins
var sass = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    cleanCSS = require('gulp-clean-css'),
    sourcemaps = require('gulp-sourcemaps');

// Variables
var 
  source = 'source/',
  target = 'public/',
  styles = {
    'in': source + 'assets/scss/app.scss',
    'out': target + 'assets/css/'
  },

// SASS
gulp.task('sass', function() {
  return gulp.src(styles.in)
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(cleanCSS())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(styles.out));
});

Here, in the sass task, styles are taken from assets/scss/app.scss, vendor prefixes are placed, all spaces / line breaks are removed and the result is placed in assets/css/
This creates a map (sourcemaps). The thing is very useful when developing: the scss file from which the rule is pulled will be shown in the element inspector. If something is not needed, just delete the unnecessary line.
Change Tracking:
// Watch tasks
gulp.task('watch', function() {
  gulp.watch(styles.in, gulp.series('sass'));
});

Please note that on the command line there is a curse that the tracking task is generated either in series or by running tasks in parallel. You can just include your array in gulp.series. The task itself can be specified in quotes, if you do not add anything, then you can remove the square brackets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question