我使用 gulp-sass、gulp-sourcemaps、browsersync 并且我的项目具有用于 sass 样式表的硬文件夹结构。现在任务看起来像这样:
gulp.task('sass', function () {
// bootstrap compilation
gulp.src('./sass/bootstrap.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass'}))
.pipe(gulp.dest('./assets/global/plugins/bootstrap/css/'))
// global theme stylesheet compilation
gulp.src('./sass/global/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/global'}))
.pipe(gulp.dest('./assets/global/css'))
gulp.src('./sass/apps/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/apps'}))
.pipe(gulp.dest('./assets/apps/css'))
gulp.src('./sass/pages/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/pages'}))
.pipe(gulp.dest('./assets/pages/css'))
// theme layouts compilation
gulp.src('./sass/layouts/layout4/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/layouts/layout4'}))
.pipe(gulp.dest('./assets/layouts/layout4/css'))
gulp.src('./sass/layouts/layout4/themes/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/layouts/layout4/themes'}))
.pipe(gulp.dest('./assets/layouts/layout4/css/themes'))
});
但我认为这项任务可能更简单。谢谢你。