gruntfile文件名为patterns,可能吗?

时间:2013-11-17 15:43:19

标签: node.js sass gruntjs glob

我正在玩Ghost,我想让gruntfile从我的主题中编译sass文件。

所以我开始修改sass任务:

...
sass: {
    admin: {
        files: {
            '<%= paths.adminAssets %>/css/screen.css': '<%= paths.adminAssets %>/sass/screen.scss'
        }
    },
    themes: {
        files:{
            'content/themes/**/css/ie.css': 'content/themes/**/src/sass/ie.sass',
            'content/themes/**/css/print.css': 'content/themes/**/src/sass/print.sass',
            'content/themes/**/css/screen.css': 'content/themes/**/src/sass/screen.sass'
        }
    }
}
...

我意识到我可以将其简化为:

...
sass: {
    admin: {
        files: {
            '<%= paths.adminAssets %>/css/screen.css': '<%= paths.adminAssets %>/sass/screen.scss'
        }
    },
    themes: {
        files:{
            'content/themes/**/css/*.css': 'content/themes/**/src/sass/*.sass',
        }
    }
}
...

但后来我在思考,为什么不用它与来源匹配的东西取代目的地的星星呢?

结束它只是创建以下内容:

$ ls -al ./content/themes/
total 0
drwxrwxr-x 1 zenobius zenobius  50 Nov 18 02:10 .
drwxrwxr-x 1 zenobius zenobius  46 Nov 15 11:02 ..
drwxrwxr-x 1 zenobius zenobius   6 Nov 18 02:10 **         <----- sigh
drwxrwxr-x 1 zenobius zenobius 128 Nov 15 11:02 casper
drwxrwxr-x 1 zenobius zenobius 250 Nov 18 00:08 crycilium

我想我的问题确实是:

  • 我可以使用某种名为pattern的正则表达式
  • 我可以使用files选项中的函数来处理输出名称作为目标吗?

1 个答案:

答案 0 :(得分:1)

所以解决方案是使用grunt.file.expandMapping,(感谢:https://stackoverflow.com/a/16672303/454615):

            ...
            themes: {
                files: grunt.file.expandMapping([
                    "content/themes/**/src/**/*.sass",
                    "!content/themes/**/src/**/_*.sass",
                  ], '', {
                  expand: true,
                  ext: '.css',
                  rename: function(base, src) {
                    grunt.log.write(base + " " + src);
                    return src.replace('/src/', '/../'); // or some variation
                  }
                })
            }
            ...