【问题标题】:Bootstrap gruntfile. How to include cssmin task into watch task引导 grunt 文件。如何将 cssmin 任务包含到监视任务中
【发布时间】:2015-05-16 09:39:07
【问题描述】:

我有一个新的 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 任务? 提前谢谢你。

【问题讨论】:

    标签: twitter-bootstrap gruntjs task gruntfile


    【解决方案1】:

    我用旧引导版本的 gruntfile 的 less 任务替换了新 gruntfile 中的整个 less 任务。这是旧的(有效):

    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'
          }
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 2013-02-23
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多