代码之家  ›  专栏  ›  技术社区  ›  Саша ЧерныÑ

使用全局模式而不是默认呼噜键

  •  1
  • Саша Ð§ÐµÑ€Ð½Ñ‹Ñ  · 技术社区  · 6 年前

    1。总结

    我不能设定 grunt-clean-console 插件,它适用于所有我的 .html 文件夹。


    2。细节

    Grunt Clean控制台检查浏览器控制台错误 HTML 文件夹。

    我想检查所有浏览器控制台错误 HTML 我网站的文件。 In official descripition 我读到了,插件是如何为特定值工作的 url 关键。我的网站上有很多页面,我不想每一页都添加 HTML 单独归档。但我找不到如何使用模式。

    我发现,我可以使用模式来内置呼噜声 cwd , src , dest 钥匙。但我如何使用glob(或其他)模式作为自定义密钥 网址 这个插件?


    三。数据

    • Gruntfile.coffee :

      module.exports = (grunt) ->
      
          grunt.loadNpmTasks 'grunt-clean-console'
      
          grunt.initConfig
              'clean-console':
                  all:
                      options:
                          url: 'output/index.html'
          return
      
    • 例子 项目配置:

      output
      │   404.html
      │   index.html
      │
      ├───KiraFirstFolder
      │       KiraFirstfile.html
      │
      └───KiraSecondFolder
              KiraSecondFile.html
      
    • 如果我为 网址 没有模式的键,如上例所示,Grunt Clean控制台成功工作:

      phantomjs: opening page output/index.html
      
      phantomjs: Checking errors after sleeping for 5000ms
      ok output/index.html
      
      phantomjs process exited with code 0
      
      Done.
      

    3.1。复制的步骤

    我在控制台中运行:

    grunt clean-console --verbose
    

    4。没有帮助

    4.1。文件名代换

    • Official documentation

    • Gruntfile.coffee咖啡 :

      module.exports = (grunt) ->
      
          grunt.loadNpmTasks 'grunt-clean-console'
      
          grunt.initConfig
              'clean-console':
                  all:
                      options:
                          url: 'output/**/*.html'
          return
      
    • 输出:

      phantomjs: opening page http://output/**/*.html
      
      phantomjs: Unable to load resource (#1URL:http://output/**/*.html)
      
      
      phantomjs:   phantomjs://code/runner.js:30 in onResourceError
      Error code: 3. Description: Host output not found
      
        phantomjs://code/runner.js:31 in onResourceError
      
      phantomjs: loading page http://output/**/*.html status fail
      
        phantomjs://code/runner.js:50
      
      phantomjs process exited with code 1
      url output/**/*.html has 1 error(s)
      >> one of the urls failed clean-console check
      Warning: Task "clean-console:all" failed. Use --force to continue.
      
      Aborted due to warnings.
      

    4.2。以常规方式构建对象

    • Official documentation

    • Gruntfile.coffee咖啡 (例):

      module.exports = (grunt) ->
      
          grunt.loadNpmTasks 'grunt-clean-console'
      
          grunt.initConfig
              'clean-console':
                  all:
                      options:
                          url:
                              files: [
                                  expand: true
                                  cwd: "output/"
                                  src: ['**/*.html']
                                  dest: "output/"
                              ]
          return
      
    • 输出:

      File: [no files]
      Options: urls=[], timeout=5, url=["output/**/*.html"]
      
      Fatal error: missing url
      

    4.3。模板

    • Official documentation

    • Gruntfile.coffee咖啡 :

      module.exports = (grunt) ->
      
          grunt.loadNpmTasks 'grunt-clean-console'
      
          grunt.initConfig
              'clean-console':
                  all:
                      options:
                          url: '<%= kiratemplate %>'
              kiratemplate: ['output/**/*.html'],
          return
      
    • 输出:

      phantomjs: opening page http://output/**/*.html
      
      phantomjs: Unable to load resource (#1URL:http://output/**/*.html)
      
      
      phantomjs:   phantomjs://code/runner.js:30 in onResourceError
      Error code: 3. Description: Host output not found
      
        phantomjs://code/runner.js:31 in onResourceError
      loading page http://output/**/*.html status fail
      
        phantomjs://code/runner.js:50
      
      phantomjs process exited with code 1
      url output/**/*.html has 1 error(s)
      >> one of the urls failed clean-console check
      Warning: Task "clean-console:all" failed. Use --force to continue.
      
      Aborted due to warnings.
      
    1 回复  |  直到 6 年前
        1
  •  1
  •   RobC Manuel Gonzalez    6 年前

    grunt.initConfig 使用的部分 grunt.file.expand . 例如:

    GruntFiel.js

    module.exports = function(grunt) {
    
      grunt.loadNpmTasks 'grunt-clean-console'
    
      // Add this function...
      function getFiles() { return grunt.file.expand('output/**/*.html'); }
    
      grunt.initConfig({
        'clean-console': {
          all: {
            options: {
              url: getFiles() // <-- invoke the function here.
            }
          }
        }
        // ...
      });
    
      // ...
    }
    

    笔记:

    • 这个 getFiles 函数返回所有文件的文件路径数组 .html 与给定全局模式匹配的文件,即 'output/**/*.html' .
    • 的值 options.url 属性设置为 getFiles() 调用函数。