该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.