【问题标题】:grunt watch and stylus咕噜声手表和手写笔
【发布时间】:2014-12-12 11:58:25
【问题描述】:

不知道如何嵌套 grunt watchstylus 编译器(livereload 稍后会出现)

我也尝试过使用“新”的 grunt newer,但我的代码一定有问题。

有什么建议吗?

grunt.initConfig({

  stylus: {
    compile: {
      options: {
        paths: ['stylus'],

        import: [      
          'nib/*'
        ]
      },
      files: {
        'css/style.css': 'stylus/style.styl', 
      },
    },

  },
  watch: {
    stylus: {
      files: ['*/*.*'],
      task: ['newer:stylus:compile'],
      options : { livereload: true },
    },
  },

});


grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');

grunt.registerTask('compile', ['newer:stylus:all']);

另外,如果我运行grunt watch,它运行良好但什么也不做。 而且,如果我运行 grunt stylus,它会完美地编译我的 css。

【问题讨论】:

    标签: javascript gruntjs stylus


    【解决方案1】:

    好吧,在您的原始代码中,当it should be tasks(复数)时,您使用选项task。这是我的第一个猜测。

    watch: {
      stylus: {
        files: ['*/*.*'],
        tasks: ['stylus:compile'],   // This needs to be "tasks" (not "task")
        options : { livereload: true },
      },
    },
    

    我也不认为您需要前面的 newer 位。

    【讨论】:

      【解决方案2】:

      我自己解决了,但我不知道是什么错误。

      pkg: grunt.file.readJSON('package.json'),
      
              stylus: {
                  all: {
                      options: {
                            paths: ['stylus'],
      
                            import: [      //  @import 'foo', 'bar/moo', etc. into every .styl file
                              'nib/*'
                            ]
                          },
                          files: {
                            'css/style.css': 'stylus/style.styl', // 1:1 compile
                          },
                  },
              },
      
              watch: {
                  files: [
                      'stylus/*.styl',
                  ],
                  tasks: ['stylus:all'],
              }
            });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-17
        • 1970-01-01
        • 2014-01-20
        • 2020-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多