Gruntjs-注意大量子目录和文件中的更改

Gruntjs - watch for changes in a large amount of subdirectories and files

本文关键字:文件 子目录 Gruntjs-      更新时间:2023-09-26

我最近刚开始使用grunt.js,我想知道是否可以监视大文件夹结构的变化?

它在小型项目文件夹结构中对我来说很好,但当我试图观看整个系统,如magento或wordpress,甚至其中的一部分时,它只是挂在那里,找不到任何更改。

我做错什么了吗?

这是我的gruntfile.js:

module.exports = function(grunt) {
grunt.initConfig({
    watch: {
        livereload: {
            files: ['template/{,*/}*'],
            options: {
                // Start a live reload server on the default port 35729
                livereload: true
            }
        }
    }
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', 'watch');
}

如果你熟悉magento,gruntfile位于中

D: ''wamp''www''magento''app''design''frontend''myTheme''default''

并在"template"文件夹及以后的文件夹中查找文件更改。

"template"文件夹中有404个文件和242个文件夹。公平地说没有那么多。。。我不明白为什么它没有立即发现变化,只是挂起了。

当只将一个子目录(例如:/page包含25个文件和4个文件夹)添加到gruntfile文件源引用时,它会立即发现更改。

示例:

files: ['template/page/{,*/}*']

我希望我能把问题讲清楚。如果有什么不清楚的地方,请告诉我。

感谢您抽出时间!

好的,我找到了解决方案。问题出在我使用的正则表达式上。

files: ['template/page/{,*/}*']

应该是:

files: ['**/*.*']

以匹配任何子目录中的任何文件。

和:

files: ['template/**/*.*']

以匹配"template"文件夹中的所有子目录和文件。