我有以下文件结构:
主题 文件夹1 -scss -style.scss 文件夹2 -scss -style.scss foldern -scss -style.scss
的package.json gulpfile.js需要……
试试这个:
var gulp = require('gulp'), sass = require('gulp-sass'), // etc. // two more plugins rename = require('gulp-rename') path = require('path'); gulp.task('sass', function () { return gulp .src('./**/scss/**/*.scss') .pipe(sourcemaps.init()) .pipe(sass({ outputStyle: 'uncompressed' }).on('error', sass.logError)) .pipe(sourcemaps.write('./')) // rename the current file's parent directory .pipe(rename(function (file) { // file.dirname = current folder, your "scss" // then get the parent of the current folder, e.g., "folder1", "folder2", etc. let parentFolder = path.dirname(file.dirname) // set each file's folder to "folder1/css", "folder2/css", etc. file.dirname = path.join(parentFolder, 'css'); })) .pipe(gulp.dest('.')); });