我的项目中的样式以这种方式组织:
styles/
/1.less
/2.less
/..
/style.less
/style.css
在 style.less 中按顺序导入:
@import '1';
@import '2';
//..
在示例中 1.less 包含 html 标签的属性,2.less 包含 body 标签的属性,3.less 包含 div 标签的属性;我希望输出应该是这样的:
html {
/*this styles first*/
}
body {
/*this styles second*/
}
div {
/*this styles third*/
}
但在编译的 style.css 中,我得到了一个重复的样式属性:
html {
/*this styles first*/
}
div {
/*this styles third*/
}
html {
/*this styles first*/
}
body {
/*this styles second*/
}
div {
/*this styles third*/
}
body {
/*this styles second*/
}
构建系统 - Gulp,gulpfile.js 看起来像这样:
'use strict';
var gulp = require('gulp'),
watch = require('gulp-watch'),
concat = require('gulp-concat'),
less = require('gulp-less'),
csso = require('gulp-csso')
var path = {
build: {
css: 'styles/'
},
src: {
style: 'styles/*.less'
}
};
gulp.task('style:build', function () {
gulp.src(path.src.style)
.pipe(less())
.pipe(concat('style.css'))
.pipe(gulp.dest(path.build.css))
});
gulp.task('build', [
'style:build'
]);
gulp.task('default', ['build']);
gulp.task('watch', function(){
gulp.watch(path.src.style, ['build']);
});
在我看来,错误在于 gulpfile.js。