-->

Grunt expand files, what patterns are acceptable i

2019-06-23 23:19发布

问题:

Snippet from gruntfile.js

sass: {
    compile: {
        files: [{
            expand: true,
            cwd: 'css/',
            src: ['^[^_].scss'],
            dest: '../css/',
            ext: '.css'
        }]
    }
},

This should work according to rubular.

Basically I want to compile all .scss files in the 'css' directory, unless they start with an underscore. However, that pattern doesn't match anything?

Any ideas?

回答1:

Try this pattern: ['*.scss', '!_*.scss']. It'll make the distinction more explicit, too.

sass: {
    compile: {
        files: [{
            expand: true,
            cwd: 'css/',
            src: ['*.scss', '!_*.scss'],
            dest: '../css/',
            ext: '.css'
        }]
    }
},

If you want to match recursively (files in subfolders of cwd), use **/*

sass: {
    compile: {
        files: [{
            expand: true,
            cwd: 'css/',
            src: ['**/*.scss', '!**/_*.scss'],
            dest: '../css/',
            ext: '.css'
        }]
    }
},

Learn more about Grunt Globbing Patterns, which aren't the same as regular expressions.