Reputation: 665
I'm trying to compile my LESS files using the gulp-useref plugin, but it is as if the gulp-less plugin never outputs a compiled version of my LESS files in the pipeline. The LESS files get concatenated with the other CSS files without being compiled.
I tried compiling my LESS separately using only gulp-less and it is working well, but I have no idea why it seems to conflict with the gulp-useref plugin.
Here is my gulpfile :
var gulp = require('gulp');
var rm = require('gulp-rimraf');
var gulpif = require('gulp-if');
var less = require('gulp-less');
var cssmin = require('gulp-minify-css');
var useref = require('gulp-useref');
gulp.task('clean', function () {
return gulp.src(['public'])
.pipe(rm({force: true}));
});
gulp.task('refs', ['clean'], function () {
var assets = useref.assets({searchPath: '.'});
return gulp.src(['templates/**/*.html'])
.pipe(assets)
.pipe(gulpif('*.less', less()))
.pipe(gulpif('*.css', cssmin()))
.pipe(assets.restore())
.pipe(gulpif('*.html', useref()))
.pipe(gulp.dest('public/templates'));
});
Thanks in advance for answers!
Upvotes: 7
Views: 1263
Reputation: 11194
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat= require('gulp-concat');
var minifyCss = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var pump = require('pump');
var useref = require('gulp-useref');
gulp.task('sass', function(){
gulp.src(['css/**/*.scss' ,'css/**/*.css' ])
.pipe(sass()) // Using gulp-sass
.pipe(minifyCss())
.pipe(concat('all.css'))
.pipe(gulp.dest('build/css'))
});
gulp.task('compressJS', function (cb) {
return gulp.src(['lib/*.js'])
.pipe(concat('concat.js'))
.pipe(uglify())
.pipe(gulp.dest('build/js'))
});
var gulp = require('gulp'),
useref = require('gulp-useref');
gulp.task('default', ['sass'] , function () {
//нема
return gulp.src('*.html')
.pipe(useref())
.pipe(gulp.dest('dist'));
});
then include file all.css genereted by gulp.task('sass')
<link rel="stylesheet" href="css/all.css" >
Upvotes: 0
Reputation: 49054
As far as i understand is what you try not possible.
with:
<!-- build:css css/combined.css -->
<link href="css/one.css" rel="stylesheet">
<link href="css/two.css" rel="stylesheet">
<link rel="stylesheet/less" type="text/less" href="less/website.less" />
<!-- endbuild -->
useref.assets creats a stream for css/combined.css which contains the content of css/one.css, css/two.css less/website.less. Because of the name of your stream is css/combined.css
only the .pipe(gulpif('*.css', cssmin()))
matches.
If you use .pipe(gulpif('*.css', less()))
, the less compiler will compile the content of all three files into css/combined.css.
So you can use:
.pipe(gulpif('*.css', less()))
.pipe(gulpif('*.css', cssmin()))
The above compiles both your *.css and *.less files with the Less compiler (cause Less can compile css, the result may as expected)
Upvotes: 3
Reputation: 45106
Try to add custom type
var assets = useref.assets({
searchPath: '.',
types: ['js', 'css', 'less']
});
Upvotes: 0