Grunt j带有正则表达式

时间:2016-05-30 13:39:49

标签: regex node.js sass gruntjs

grunt.config('sass', {
    options: {
      sourceMap: true
    },
    dist: {
      options: {
        outputStyle: 'compact'
      },
      files: {
        '/css/site.css': 'main/scss/site.scss',
        '/css/template.home.css': 'main/scss/templates/home.scss'
        '/css/template.contact.css': 'main/scss/templates/contact.scss'
        '/css/template.something.css': 'main/scss/templates/something.scss'
      }
    }
});

有没有办法很好地处理这个部分(考虑模式,但我不确定可能性)

'/css/template.home.css': 'main/scss/templates/home.scss'
'/css/template.contact.css': 'main/scss/templates/contact.scss'
'/css/template.something.css': 'main/scss/templates/something.scss'

1 个答案:

答案 0 :(得分:2)

如果将配置声明为JS对象,则可以这样做:



var cfg = {
        options: {
            sourceMap: true
        },
        dist: {
            options: {
                outputStyle: 'compact'
            },
            files: {
                '/css/site.css': 'main/scss/site.scss',
                '/css/template.home.css': 'main/scss/templates/home.scss',
                '/css/template.contact.css': 'main/scss/templates/contact.scss',
                '/css/template.something.css': 'main/scss/templates/something.scss'
            }
        }
    },
    grunt = {
      config: function() {
        document.write('<br/><strong>grunt config set</string><br/>');
      }
    };

    document.write('<br/>"files" before new config:<br/><br/>');

    for (var property in cfg.dist.files) {
        if (cfg.dist.files.hasOwnProperty(property)) {
            document.write(property + ' = ' + cfg.dist.files[property] + '<br/>');
        }
    }

    document.write('<br/>"files" after added config:<br/><br/>');

    cfg.dist.files['/css/what ever...'] = 'the/latest/path';

    for (var property in cfg.dist.files) {
        if (cfg.dist.files.hasOwnProperty(property)) {
            document.write(property + ' = ' + cfg.dist.files[property] + '<br/>');
        }
    }

    grunt.config('sass', cfg);
&#13;
&#13;
&#13;

注意

    cfg.dist.files['/css/what ever...'] = 'the/latest/path';

添加附加配置的地方。