尝试创建一个gulp文件,用于获取LESS文件并生成相应的.css,.min.css和.css.map文件。关闭,但是sourcemaps正在将地图写入扩展名为.css.min.css。
的文件/// <vs BeforeBuild='less' SolutionOpened='less' />
/// <binding BeforeBuild='less' ProjectOpened='less' />
var gulp = require('gulp');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var minifycss = require('gulp-minify-css');
var pleeease = require('gulp-pleeease');
var rename = require('gulp-rename');
var mqpacker = require('css-mqpacker');
var csswring = require('csswring');
var postcss = require('gulp-postcss');
var processors = [
autoprefixer({ browsers: ["IE >= 9, firefox > 10, last 2 Chrome versions, last 2 safari versions, last 2 ios versions"] }),
mqpacker
];
gulp.task('less', function () {
gulp.src('./itims/Content/*.less', { base: './itims/content'})
.pipe(sourcemaps.init())
.pipe(less())
.pipe(postcss(processors))
.pipe(rename({
extname: '.css'
}))
.pipe(gulp.dest('./itims/content'))
.pipe(minifycss())
.pipe(sourcemaps.write('./'))
.pipe(rename({
suffix: '.min',
extname: '.css'
}))
.pipe(gulp.dest('./itims/content'));
});
答案 0 :(得分:3)
正如您可能猜到的那样,您的问题来自于rename
之后的sourcemaps.write
。您只想重命名*.css
个文件,因此以下解决方案应该可以解决这个问题:
将gulp-if
添加到依赖项(如果尚未存在)
var if = require('gulp-if');
按如下方式重写您的任务:
gulp.src('./itims/content/*.less', {base: './itims/content'})
.pipe(sourcemaps.init())
.pipe(less())
.pipe(postcss(processors))
.pipe(gulp.dest('./itims/content'))
.pipe(minifycss())
.pipe(sourcemaps.write('./'))
.pipe(if('*.css', rename({extname: '.min.css'}))
.pipe(gulp.dest('./itims/content'));
注意:
*.less
重命名为*.css
'./itims/Content'
和'./itims/content'
。