Css 如何查看导入其他文件的一个文件?

Css 如何查看导入其他文件的一个文件?,css,gulp,Css,Gulp,我的sass结构是这样的 - /base -- _fonts.scss -- _all.scss - /components -- _all.scss -- _header.scss -- _footer.scss - main.scss 每个_all.scss导入当前文件夹中的所有文件,然后main.scss导入每个文件夹中的所有文件 我面临的问题是,我实际上需要保存main.scs,以便gulp生成.css文件。如果我查看所有

我的sass结构是这样的

    - /base
    -- _fonts.scss
    -- _all.scss
    - /components
    -- _all.scss
    -- _header.scss
    -- _footer.scss
    - main.scss
每个_all.scss导入当前文件夹中的所有文件,然后main.scss导入每个文件夹中的所有文件

我面临的问题是,我实际上需要保存main.scs,以便gulp生成.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']);
});
如何让gulp监视所有文件,并在公用文件夹中只生成一个css文件?

我是这样做的

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

});
请在此处查找全文:

希望这能有所帮助。

以下是我的做法

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

});
请在此处查找全文:

希望这有帮助