【问题标题】:Gruntjs - watch for changes in a large amount of subdirectories and filesGruntjs - 监视大量子目录和文件的变化
【发布时间】:2023-03-08 11:53:01
【问题描述】:

我最近才开始使用 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\

并在“模板”文件夹中查找文件更改。

“模板”文件夹中有 404 个文件和 242 个文件夹。公平地说,这并不多...我不明白为什么它几乎没有立即找到更改而只是挂起。

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

示例:

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

我希望我设法足够清楚地通过了我的问题。如果有什么不清楚的地方请告诉我。

感谢您的宝贵时间!

【问题讨论】:

    标签: javascript node.js filesystems gruntjs grunt-contrib-watch


    【解决方案1】:

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

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

    应该是:

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

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

    和:

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

    匹配“模板”文件夹中的所有子目录和文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多