Answer the question
In order to leave comments, you need to log in
Gulp scss why compilation error with nested elements?
Hello
As long as the elements in the scss file are not nested, then everything is fine, I just do something like this
body {
margin: 0;
a {
margin: 0;
}
}
{
"name": "static-new",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"dependencies": {},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^6.0.0",
"gulp-clean-css": "^3.10.0",
"gulp-concat-css": "^3.1.0",
"gulp-rigger": "^0.5.8",
"gulp-sass": "^4.0.1",
"gulp-uglify": "^3.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
let gulp = require('gulp');
let sass = require('gulp-sass');
let autoprefixer = require('gulp-autoprefixer');
let concatCss = require('gulp-concat-css');
let cleanCSS = require('gulp-clean-css');
let uglify = require('gulp-uglify');
//paths
let scssFiles = 'frontend/scss/**/*.scss';
let cssDist = 'dist/css/';
let jsFiles = 'frontend/js/**/*.js';
let jsDist = 'dist/js/';
gulp.task('watch',function() {
gulp.watch(scssFiles,['build-css']);
gulp.watch(jsFiles,['build-js']);
});
gulp.task('build-css', function(){
gulp.src(scssFiles)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(concatCss("style.css"))
.pipe(cleanCSS())
.pipe(sass())
.pipe(gulp.dest(cssDist));
});
gulp.task('build-js', function() {
gulp.src(jsFiles) //Найдем наш main файл
.pipe(uglify()) //Сожмем наш js
.pipe(gulp.dest(jsDist)) //Выплюнем готовый файл в build
});
Answer the question
In order to leave comments, you need to log in
Wrong order of execution, you need to sass() first
Something like this (might not work, not tested)
gulp.task('build-css', function(){
gulp.src(scssFiles)
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(concatCss("style.css"))
.pipe(cleanCSS())
.pipe(gulp.dest(cssDist));
});
gulp.task('sass', () =>
gulp.src(variables.src.scss)
.pipe(errorNotifier.handleError(sass()))
.pipe(autoPrefixer({
browsers: ['last 2 versions', 'safari 5', 'ie 11', 'opera 12.1', 'ios 6', 'android 4'],
cascade: false
}))
.pipe(combineMq({
beautify: true
}))
.pipe(gulp.dest(variables.public.css))
.pipe(notify('Sass compile!'))
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question