css - Gulp中如何匹配返回各种扩展名的文件?

标签 css regex gulp stylus file-globs

我试图返回位于不同文件夹中的扩展名为 .css 和 .styl 的文件,并在 Gulp 任务中使用它们,但没有取得太大成功。我想知道我在这里做错了什么?这是我此时的代码:

var pattrn = /(styl|css)$/g;
var path1 = './dev/**/';

var paths = {
  dev_styles: path1.match( pattrn ),
  build: './build'
};

gulp.task( 'styles', function() {
  var processors = [
    csswring,
    autoprefixer( { browsers: [ 'last 2 version' ] } )
];

return gulp
  .src( paths.dev_styles )
  .pipe( plugins.postcss( processors ) )
  .pipe( plugins.rename( { suffix: '.min'} ) )
  .pipe( gulp.dest( paths.build ) );
});

我收到这个错误:

Error: Invalid glob argument: null

最佳答案

嗯,你的问题是 gulp 不是这样工作的。

检查 documentation关于 gulp.src,它指出:

gulp.src(globs[, options]) accept glob or array of globs to read.

这意味着你不需要做花哨的(奇怪的)过滤,指定一个合适的 node-glob syntax就足够了。

回到你的问题,这将解决它:

gulp.task( 'styles', function() {
  var processors = [
    csswring,
    autoprefixer( { browsers: ['last 2 version' ] } )
  ];
  return gulp
    .src( 'root_to_styl_files/**/*.styl' ) // Will get all .styl files in the specified folder & subfolders
    .pipe( plugins.postcss( processors ) )
    .pipe( plugins.rename( { suffix: '.min' } ) )
    .pipe( gulp.dest( './build' ) );
});

关于css - Gulp中如何匹配返回各种扩展名的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34043990/

相关文章:

css - 如何在浏览器大小变化时内联显示多个 100% 宽度的 <li>?

HTML:文本、标题、副行

regex - 在文本文件中按列对唯一元素进行排序

javascript - NodeJS & Gulp Streams & Vinyl File Objects - Gulp Wrapper for NPM package producing incorrect output

gulp - 使用 gulp 自动添加灵活性声明

javascript - 如何在 pm2 中使用 Grunt/Gulp?

html - 如何更改 Bootstrap 中 Accordion 选项卡的背景颜色?

用于搜索子字符串的Python正则表达式

java - 如何格式化或解析 SOAP 原始对象

html - 使用溢出时出现空白 : auto or scroll on table