Bootstrap gruntfile。如何将cssmin任务包含在监视任务中

时间:2015-05-16 09:39:08

标签: twitter-bootstrap gruntjs task gruntfile

我有一个新的Bootstrap项目。一切正常,livereload,grunt命令,watch命令和cssmin命令,所以这些任务都可以。

但是,当我运行grunt watch时,没有生成缩小的css文件(我的意思是,当文件更改和监视任务自动运行时)。所以,我需要添加cssmin任务来监视gruntfile中的任务。我不知道怎么做。我的gruntfile监视任务看起来像:

watch: {
  options: {
   livereload: true,
  }, 
  src: {
    files: '<%= jshint.core.src %>',
    tasks: ['jshint:src', 'qunit', 'concat']
  },
  test: {
    files: '<%= jshint.test.src %>',
    tasks: ['jshint:test', 'qunit']
  },
  less: {
    files: 'less/**/*.less',
    tasks: 'less'
  }
},

如何添加cssmin任务? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我在新的gruntfile中用较少的任务来替换旧的bootstrap版本的grunt文件。这是旧的(它有效):

less: {
      compileCore: {
        options: {
          strictMath: true,
          sourceMap: true,
          outputSourceFiles: true,
          sourceMapURL: '<%= pkg.name %>.css.map',
          sourceMapFilename: 'dist/css/<%= pkg.name %>.css.map'
        },
        files: {
          'dist/css/<%= pkg.name %>.css': 'less/bootstrap.less'
        }
      },
      compileTheme: {
        options: {
          strictMath: true,
          sourceMap: true,
          outputSourceFiles: true,
          sourceMapURL: '<%= pkg.name %>-theme.css.map',
          sourceMapFilename: 'dist/css/<%= pkg.name %>-theme.css.map'
        },
        files: {
          'dist/css/<%= pkg.name %>-theme.css': 'less/theme.less'
        }
      },
      minify: {
        options: {
          cleancss: true,
          report: 'min'
        },
        files: {
          'dist/css/<%= pkg.name %>.min.css': 'dist/css/<%= pkg.name %>.css',
          'dist/css/<%= pkg.name %>-theme.min.css': 'dist/css/<%= pkg.name %>-theme.css'
        }
      }
    },

这是新版本(不会起作用):

less: {
      compileCore: {
        options: {
          strictMath: true,
          sourceMap: true,
          outputSourceFiles: true,
          sourceMapURL: '<%= pkg.name %>.css.map',
          sourceMapFilename: 'dist/css/<%= pkg.name %>.css.map'
        },
        src: 'less/bootstrap.less',
        dest: 'dist/css/<%= pkg.name %>.css'
      },
      compileTheme: {
        options: {
          strictMath: true,
          sourceMap: true,
          outputSourceFiles: true,
          sourceMapURL: '<%= pkg.name %>-theme.css.map',
          sourceMapFilename: 'dist/css/<%= pkg.name %>-theme.css.map'
        },
        src: 'less/theme.less',
        dest: 'dist/css/<%= pkg.name %>-theme.css'
      }
    },