Answer the question
In order to leave comments, you need to log in
Why are variables lost in less when building in gulp?
Hello, I recently set up a gulpfile for building less layout, put all the variables into a separate less file, I import this file into General.less with all styles, however, when building through gulp-less, the output is an empty css file, and gulp complains that that we are using non-created variables.
const gulp = require('gulp'),
concat = require('gulp-concat-css'),
cleanCSS = require('gulp-clean-css'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
path = require('path')
gulp.task('less', done => {
gulp.src('./src/**/*.less')
.pipe( less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
//.pipe( concat('General.css'))
.pipe( autoprefixer({
browsers: ['last 2 version'],
cascade: false
}))
.pipe( cleanCSS({ level: 2 }))
.pipe( gulp.dest('./build/style/'))
done()
})
gulp.task('assets', done => {
gulp.src('./assets/css/**/*.css')
.pipe( concat('Assets.css'))
.pipe( cleanCSS({ level: 2 }))
.pipe( gulp.dest('./build/style/'))
done()
})
gulp.task('default', gulp.parallel(
'assets',
'less'
))
gulp.watch('./src/**/*.less', gulp.series('less'))
Answer the question
In order to leave comments, you need to log in
And actually, because you NEED to concatenate less first and only then compile, use gulp-concat.
Firstly, you don’t need to concatenate less, and secondly: check the paths to the files, apparently there are errors, or if your concatenation was immediately in the assembly, then maybe it ate variables? The concat is called css-concat, it could skip variables, and then the loess compiler does not see them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question