如何观看一个导入其他文件的大文件?
问题描述:
我的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文件?
答
以下是我的操作方法。
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/
希望这有助于。