2017-07-03 61 views
1

我的sass結構看起來像這樣。如何觀看一個導入其他文件的大文件?

- /base 
    -- _fonts.scss 
    -- _all.scss 
    - /components 
    -- _all.scss 
    -- _header.scss 
    -- _footer.scss 
    - main.scss 

每個_all.scss進口的所有文件在當前文件夾,然後將main.scss進口的每個文件夾的所有_all文件。

我面臨的問題是我實際上需要保存main.scss以便吞噬生成.css文件。如果我觀察所有文件,它會生成很多我不需要的.css文件。

gulpfile.js

'use strict'; 

var gulp = require('gulp'); 
var sass = require('gulp-sass'); 

gulp.task('sass', function() { 
    return gulp.src('./src/stylesheets/main.scss') 
    .pipe(sass().on('error', sass.logError)) 
    .pipe(gulp.dest('./public/css/')); 
}); 

gulp.task('sass:watch', function() { 
    gulp.watch('./src/stylesheets/main.scss', ['sass']); 
}); 

如何使大口看的所有文件,並生成公共文件夾中只有一個css文件?

回答

0

以下是我的操作方法。

Main.scss

@import "your/relative/path/of/your/_partial-file1"; 
@import "your/relative/path/of/your/_partial-file2"; 

/*Other scss stylings if needed*/ 

在你gulpfile.js,添加SASS任務

gulp.task('css',()=>{ 

 return gulp.src('src/scss/*.scss') //target all the .css files in the specified directory 

   .pipe(sass()) //gulp-sass module to convert scss files into css file 

   .pipe(minifyCSS()) //method to minify the final css file 

   .pipe(gulp.dest('build/css')); //outputs final css file into the specified directory 

   console.log('CSS build'); 

}); 



gulp.task('default', [ 'css','your', 'other','tasks' ],()=>{ 

console.log("All done. Watching files..."); 



 //watch the files in the specified directory. 

 //if any changes are made to the files, the specified task will be executed in the watch method 

gulp.watch('src/**/*.scss',['css']); 

}); 

找到完整的文章在這裏:http://todarman.com/gulp-configuration-build-html-css-js/

希望這有助於。