├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── gruntfile.js ├── license ├── package.json ├── readme.md ├── tasks └── cssnano.js └── test ├── fixture.css └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '12' 4 | - '10' 5 | - '8' 6 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = grunt => { 4 | grunt.initConfig({ 5 | cssnano: { 6 | compile: { 7 | files: { 8 | 'test/tmp/fixture.css': 'test/fixture.css' 9 | } 10 | } 11 | }, 12 | nodeunit: { 13 | tasks: [ 14 | 'test/test.js' 15 | ] 16 | }, 17 | clean: { 18 | test: [ 19 | 'test/tmp/**' 20 | ] 21 | } 22 | }); 23 | 24 | grunt.loadTasks('tasks'); 25 | grunt.loadNpmTasks('grunt-contrib-clean'); 26 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 27 | 28 | grunt.registerTask('default', [ 29 | 'clean', 30 | 'cssnano', 31 | 'nodeunit', 32 | 'clean' 33 | ]); 34 | }; 35 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-cssnano", 3 | "version": "3.0.0", 4 | "description": "Minify CSS", 5 | "license": "MIT", 6 | "repository": "sindresorhus/grunt-cssnano", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && grunt" 17 | }, 18 | "files": [ 19 | "tasks" 20 | ], 21 | "keywords": [ 22 | "gruntplugin", 23 | "css", 24 | "style", 25 | "stylesheet", 26 | "minify", 27 | "compress", 28 | "cssnano", 29 | "nano", 30 | "optimize", 31 | "optimise", 32 | "optimization", 33 | "optimisation", 34 | "postcss" 35 | ], 36 | "dependencies": { 37 | "cssnano": "^3.10.0" 38 | }, 39 | "devDependencies": { 40 | "grunt": "^1.0.1", 41 | "grunt-cli": "^1.2.0", 42 | "grunt-contrib-clean": "^2.0.0", 43 | "grunt-contrib-nodeunit": "^2.0.0", 44 | "xo": "^0.24.0" 45 | }, 46 | "peerDependencies": { 47 | "grunt": ">=1" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # grunt-cssnano [![Build Status](https://travis-ci.org/sindresorhus/grunt-cssnano.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-cssnano) 2 | 3 | > Minify CSS using [`cssnano`](https://github.com/cssnano/cssnano) 4 | 5 | *Issues with the output should be reported on the [`cssnano` issue tracker](https://github.com/ben-eb/cssnano/issues).* 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install --save-dev grunt-cssnano 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ```js 18 | require('load-grunt-tasks')(grunt); 19 | 20 | grunt.initConfig({ 21 | cssnano: { 22 | options: { 23 | sourcemap: true 24 | }, 25 | dist: { 26 | files: { 27 | 'dist/app.css': 'src/app.css' 28 | } 29 | } 30 | } 31 | }); 32 | 33 | grunt.registerTask('default', ['cssnano']); 34 | ``` 35 | 36 | 37 | ## Options 38 | 39 | See the [`cssnano` options](https://github.com/ben-eb/cssnano#options). 40 | -------------------------------------------------------------------------------- /tasks/cssnano.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const cssnano = require('cssnano'); 3 | 4 | module.exports = grunt => { 5 | grunt.registerMultiTask('cssnano', 'Minify CSS', function () { 6 | const done = this.async(); 7 | const options = this.options(); 8 | 9 | (async () => { 10 | await Promise.all(this.files.map(async file => { 11 | const result = await cssnano.process(grunt.file.read(file.src[0]), options); 12 | grunt.file.write(file.dest, result.css); 13 | })); 14 | 15 | done(); 16 | })().catch(grunt.fatal); 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /test/fixture.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #ffffff; 3 | } 4 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const fs = require('fs'); 3 | 4 | exports.cssnano = { 5 | minify(test) { 6 | const code = fs.readFileSync('test/tmp/fixture.css', 'utf8'); 7 | test.strictEqual(code.trim(), 'body{color:#fff}'); 8 | test.done(); 9 | } 10 | }; 11 | --------------------------------------------------------------------------------