0

grunt-contrib-less软件包提供了选项compress,它应该允许管理目标 CSS 文件的丑化/缩小/压缩。它是boolean具有默认值的false

出于任何原因,它对我不起作用——无论我将参数设置为什么,输出的 CSS 文件都会被压缩。何让它正常工作?


Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    less: {
      development: {
        options: {
          paths: ["public/css"],
          compress: false
        },
        files: {
          "public/css/style.css": "public/css/style.less"
        }
      },
      production: {
        options: {
          paths: ["public/css"],
          compress: false,
          plugins: [
            new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]}),
            new (require('less-plugin-clean-css'))([])
          ],
          modifyVars: {
          }
        },
        files: {
          "public/css/style.css": "public/css/style.less"
        }
      }
    }
  });

  // Load the plugin that provides the "less" task.
  grunt.loadNpmTasks('grunt-contrib-less');

  // Default task(s).
  grunt.registerTask('default', ['less']);

};

命令行界面

$ grunt --version
grunt-cli v0.1.13
grunt v0.4.5
$ grunt
Running "less:development" (less) task
File public/css/style.css created

Running "less:production" (less) task
File public/css/style.css created

Done, without errors.
4

1 回答 1

1

这是我的错... CSS 文件已被压缩,因为less-plugin-clean-css. 在我删除它之后,可以通过compress参数再次管理压缩。

于 2015-04-01T12:45:43.283 回答