【发布时间】:2016-06-27 15:30:11
【问题描述】:
我知道 GULP-SASS 应该是微不足道和简单的,但如果我们可以把事情复杂化,为什么不做对呢?
嗯,我工作的项目似乎有一个“特殊”的结构,我必须习惯它。是这样的:
-static
-app
-components
-component1
-styles
-component1.scss
-component2
-styles
-component2.scss
...
在与应用程序相同的级别上,我挥动了一个子项目......我们称之为网络:
-static
-web
-res
-static
-app
-components
-component3
-style
-component3.scss
现在有趣的部分来了:我怎样才能从这个混乱中创建一个单独的 CSS 文件?我试过这个没有任何运气:
// Setting up the sass task
gulp.task('sass', function (){
// Taking the path from the above object
var sassApp = gulp.src(paths.styles.filesApp)
// Sass options - make the output compressed and add the source map
// Also pull the include path from the paths object
.pipe(sass({
outputStyle: 'compact', //compressed
//sourceComments: 'map',
includePaths : [paths.styles.srcApp]
}))
// If there is an error, don't stop compiling but use the custom displayError function
.on('error', function(err){
displayError(err);
})
// Pass the compiled sass through the prefixer with defined
.pipe(prefix(
'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'
))
// Funally put the compiled sass into a css file
.pipe(gulp.dest(paths.styles.dest));
var sassWeb = gulp.src(paths.styles.filesWeb)
// Sass options - make the output compressed and add the source map
// Also pull the include path from the paths object
.pipe(sass({
outputStyle: 'compact',
//sourceComments: 'map',
includePaths : [paths.styles.srcWeb]
}))
// If there is an error, don't stop compiling but use the custom displayError function
.on('error', function(err){
displayError(err);
})
// Pass the compiled sass through the prefixer with defined
.pipe(prefix(
'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'
))
// Funally put the compiled sass into a css file
.pipe(gulp.dest(paths.styles.dest));
return
gulpMerge(sassApp, sassWeb)
.pipe(concat('all-css.css'))
.pipe(gulp.dest(paths.styles.dest));
});
【问题讨论】:
-
我会将你所有的 .scss 文件移动到一个文件夹中并使用 gulp-useref npmjs.com/package/gulp-useref