【问题标题】:gulp.dest() ignoring subdirectorygulp.dest() 忽略子目录
【发布时间】:2015-02-01 19:11:19
【问题描述】:

我的文件夹树

public_html/
- css/
- - bootstrap.css
- - theme.css
- scss/
- - bootsrap/
- - - bootstrap.scss
- - theme/
- - - theme.scss

我的 gulpfile :

var gulp = require('gulp');

//Plugins
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');

var scssPath = './public_html/scss/**/*.scss';
var cssPath = './public_html/css/';

//Compile Styles
gulp.task('CompileSASS', function () {
    gulp.src(scssPath)
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(autoprefixer())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(cssPath))
});

gulp.task('watchSASS', function () {
    gulp.watch(scssPath, ['CompileSASS']);
});

gulp.task('default', ['CompileSASS', 'watchSASS']);

会发生什么

当我运行 gulpfile 的默认方法时,生成的 CSS 文件会保存在 CSS 文件夹的子文件夹中。

/public_html/css/bootstrap/bootstrap.css

/public_html/css/主题/theme.css


需要什么

我不想将它们保存在单独的文件夹中。

如何将所有生成的 CSS 文件直接保存在 CSS 目录中,例如:

/public_html/css/bootstrap.css

/public_html/css/theme.css

【问题讨论】:

    标签: node.js gulp gulp-sass


    【解决方案1】:

    你应该看看gulp-rename

    试试:

    var gulp = require('gulp');
    
    //Plugins
    var sass = require('gulp-sass');
    var autoprefixer = require('gulp-autoprefixer');
    var sourcemaps = require('gulp-sourcemaps');
    var rename = require('gulp-rename');
    
    var scssPath = './public_html/scss/**/*.scss';
    var cssPath = './public_html/css/';
    
    //Compile Styles
    gulp.task('CompileSASS', function () {
        gulp.src(scssPath)
            .pipe(sourcemaps.init())
            .pipe(sass())
            .pipe(autoprefixer())
            .pipe(sourcemaps.write())
            //--------
            .pipe(rename({dirname: cssPath}))
            //--------
            .pipe(gulp.dest('./'))
    });
    
    gulp.task('watchSASS', function () {
        gulp.watch(scssPath, ['CompileSASS']);
    });
    
    gulp.task('default', ['CompileSASS', 'watchSASS']);
    

    【讨论】:

    • 这将如何适用于多种文件类型?例如,如果您将一些 JS 文件、CSS、index.html 复制到一个目录,并且您想要维护 cssjs 目录?
    猜你喜欢
    • 1970-01-01
    • 2011-08-12
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2011-04-27
    • 2015-01-23
    相关资源
    最近更新 更多