2017-07-03 4 views
1

Meine Sass Struktur sieht so aus.Wie man eine Schluckakte sieht, die andere importiert?

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

Jede _all.scss importiert alle Dateien im aktuellen Ordner, dann die main.scss importiert alle _all Dateien aus jedem Ordner.

Das Problem, mit dem ich konfrontiert bin, ist, dass ich main.scss speichern muss, damit Schluck die .css-Datei erzeugt. Wenn ich alle Dateien anschaue, werden viele CSS-Dateien erzeugt, die ich nicht brauche.

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']); 
}); 

Wie mache ich schluck alle Dateien sieht und nur eine CSS-Datei in dem öffentlichen Ordner erzeugen?

Antwort

0

Hier ist, wie ich es mache.

Main.scss

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

/*Other scss stylings if needed*/ 

In Ihrem gulpfile.js, fügen Sie den Sass Aufgabe

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']); 

}); 

Finden Sie den ganzen Artikel hier: http://todarman.com/gulp-configuration-build-html-css-js/

Hoffnung, das hilft.

Verwandte Themen