Skip to content

Commit 6b60ea4

Browse files
Rewrote plugin, added css purge v3
Signed-off-by: Dominik Wilkowski <Hi@Dominik-Wilkowski.com>
1 parent 45d4c2d commit 6b60ea4

File tree

12 files changed

+4987
-828
lines changed

12 files changed

+4987
-828
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ tmp
88
.idea
99
dist
1010
distall
11+
temp

Gruntfile.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,73 @@
22
* grunt-css-purge
33
* https://github.com/dominikwilkowski/grunt-css-purge
44
*
5-
* Copyright (c) 2014 Dominik Wilkowski
6-
* Licensed under the MIT license.
5+
* Copyright (c) 2018 Dominik Wilkowski
6+
* Licensed under the GNU GPL2 license.
77
*/
88

99
'use strict';
1010

1111
module.exports = function( grunt ) {
12-
// load all npm grunt tasks
1312
require( 'load-grunt-tasks' )( grunt );
1413

15-
// Project configuration.
1614
grunt.initConfig({
17-
jshint: {
18-
all: [
19-
'Gruntfile.js',
20-
'tasks/*.js',
21-
'<%= nodeunit.tests %>',
22-
],
23-
options: {
24-
jshintrc: '.jshintrc',
25-
reporter: require( 'jshint-stylish' ),
26-
},
27-
},
28-
29-
// Before generating any new files, remove any previously-created files.
3015
clean: {
31-
tests: ['tmp'],
16+
tests: ['test/temp'],
3217
},
3318

34-
// Configuration to be run (and then tested).
3519
css_purge: {
20+
21+
// Default options in src / dest notation
3622
default_options: {
37-
options: {
38-
},
23+
options: {},
24+
src: 'test/css/test.css',
25+
dest: 'test/temp/default_options.css',
26+
},
27+
28+
// Default options with multiple files in src / dest notation
29+
multiple_files: {
30+
options: {},
31+
src: [
32+
'test/css/test.css',
33+
'test/css/subfolder/test2.css',
34+
],
35+
dest: 'test/temp/multiple_files.css',
36+
},
37+
38+
// Default options with multiple files in files notation
39+
multiple_files2: {
40+
options: {},
3941
files: {
40-
'tmp/purged.css': 'test/fixtures/test.css',
42+
'test/temp/multiple_files2.css': ['test/css/test.css', 'test/css/subfolder/test2.css'],
4143
},
4244
},
45+
46+
// Default options with multiple files with wildcard in files notation
47+
multiple_files3: {
48+
options: {},
49+
files: [{
50+
src: ['test/css/**/*.css'],
51+
dest: 'test/temp/multiple_files3.css',
52+
}],
53+
},
54+
55+
// Custom options
4356
custom_options: {
4457
options: {
45-
"verbose": true,
46-
"no_duplicate_property": false,
47-
},
48-
files: {
49-
'tmp/purged-custom.css': 'test/fixtures/test.css',
58+
trim_comments: false,
59+
generate_report: true,
5060
},
61+
src: 'test/css/test.css',
62+
dest: 'test/temp/default_options.css',
5163
},
5264
},
5365

54-
// Unit tests.
55-
nodeunit: {
56-
tests: ['test/*_test.js'],
57-
},
58-
5966
});
6067

61-
// Actually load this plugin's task(s).
6268
grunt.loadTasks('tasks');
6369

64-
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
65-
// plugin's task(s), then test the result.
66-
grunt.registerTask('test', ['clean', 'css_purge', 'nodeunit']);
70+
grunt.registerTask('test', ['clean', 'css_purge']);
6771

68-
// By default, lint and run all tests.
69-
grunt.registerTask('default', ['jshint', 'test']);
72+
grunt.registerTask('default', ['test']);
7073

7174
};

README.md

Lines changed: 95 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,146 @@
1-
grunt-css-purge
1+
<img alt="Grunt CSS Purge" src="https://raw.githubusercontent.com/rbtech/css-purge/master/assets/images/grunt-css-purge.png" width="133px">
2+
3+
4+
Grunt CSS-PURGE
25
===============
36

4-
> Grunt plugin to run [CSS-Purge](https://github.com/rbtech/css-purge)
7+
Purges duplicate CSS rules and more. Based on [css-purge](https://www.npmjs.org/package/css-purge).
58

6-
[![NPM](https://nodei.co/npm/grunt-css-purge.png)](https://nodei.co/npm/grunt-css-purge/)
79

8-
## Getting Started
9-
This plugin requires Grunt.
10+
## You have an issue?
11+
12+
This is a simple [grunt](http://gruntjs.com/) plugin, which means it’s a thin wrapper around `css-purge`. If you are having CSS issues, please
13+
contact [css-purge](https://github.com/rbtech/css-purge/issues). Please only create a new issue if it looks like you’re having a problem with the grunt plugin.
1014

11-
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide,
12-
as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar
13-
with that process, you may install this plugin with this command:
1415

15-
```shell
16+
## Install
17+
18+
```
1619
npm install grunt-css-purge --save-dev
1720
```
1821

22+
23+
## Options
24+
25+
Visit the [CSS-PURGE website](http://rbtech.github.io/css-purge)
26+
27+
28+
## Getting Started
29+
30+
This plugin requires Grunt.
31+
32+
If you haven’t used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide,
33+
as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you’re familiar
34+
with that process, you may install this plugin.
1935
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
2036

2137
```js
2238
grunt.loadNpmTasks('grunt-css-purge');
2339
```
2440

25-
## The "css_purge" task
2641

27-
### Overview
28-
In your project's Gruntfile, add a section named `css_purge` to the data object passed into `grunt.initConfig()`.
42+
## Example use cases
43+
44+
The most basic `Gruntfile.js` setup:
2945

3046
```js
31-
grunt.initConfig({
32-
css_purge: {
33-
options: {
34-
"verbose": false,
35-
"no_duplicate_property": true,
36-
},
37-
files: {
38-
'purged.css': 'bigFile.css',
47+
'use strict';
48+
49+
module.exports = function( grunt ) {
50+
grunt.loadNpmTasks('grunt-css-purge');
51+
52+
grunt.initConfig({
53+
css_purge: {
54+
site: {
55+
options: {},
56+
src: 'site.css',
57+
dest: 'site.min.css',
58+
},
3959
},
40-
},
41-
})
60+
});
61+
62+
grunt.registerTask('default', ['css_purge']);
63+
};
4264
```
4365

44-
### Options
66+
For more infos about the options please look at the [CSS-Purge website](http://rbtech.github.io/css-purge/).
4567

46-
#### options.verbose
47-
Type: `Boolen`
48-
Default value: `false`
68+
See below a couple different ways you can use the grunt task with various different files.
4969

50-
Show trace of optimization
70+
A single file:
5171

52-
#### options.no_duplicate_property
53-
Type: `Boolen`
54-
Default value: `true`
72+
```js
73+
default_options: {
74+
options: {},
75+
src: 'site.css',
76+
dest: 'site.min.css',
77+
},
78+
```
5579

56-
Allow duplicate properties on a selector
80+
Multiple files:
5781

58-
### Usage Examples
82+
```js
83+
multiple_files: {
84+
options: {},
85+
src: [
86+
'site1.css',
87+
'site2.css',
88+
],
89+
dest: 'site.min.css',
90+
},
91+
```
5992

60-
#### Default Options
93+
Multiple files:
6194

6295
```js
63-
css_purge: {
96+
multiple_files2: {
97+
options: {},
6498
files: {
65-
'purged.css': 'bigFile.css',
99+
'site.min.css': ['site1.css', 'site2.css'],
66100
},
67101
},
68102
```
69103

70-
#### Custom Options
104+
Multiple files with a wildcard:
71105

72106
```js
73-
css_purge: {
107+
multiple_files3: {
108+
options: {},
109+
files: [{
110+
src: ['css/**/*.css'],
111+
dest: 'site.min.css',
112+
}],
113+
},
114+
```
115+
116+
Custom options:
117+
118+
```js
119+
custom_options: {
74120
options: {
75-
"verbose": false,
76-
"no_duplicate_property": true,
77-
},
78-
files: {
79-
'purged.css': 'bigFile.css',
121+
trim_comments: false,
122+
generate_report: true,
80123
},
124+
src: 'site.css',
125+
dest: 'site.min.css',
81126
},
82127
```
83128

129+
84130
## Contributing
131+
85132
In lieu of a formal styleguide, take care to maintain the existing coding style.
86-
Add unit tests for any new or changed functionality. Lint and test your code using the [Grunt](http://gruntjs.com/) task already set up.
133+
87134

88135
## Release History
136+
137+
* 1.0.0 - Updated to CSS-Purge 3.0.0
89138
* 0.0.4 - Updated peerDependencies for grunt 1.0
90139
* 0.0.3 - updated license
91140
* 0.0.2 - refinements
92141
* 0.0.1 - alpha test
93142

143+
94144
## License
95-
Copyright (c) 2014 Dominik Wilkowski. Licensed under the GPLv2 license.
145+
146+
Copyright (c) 2018 Dominik Wilkowski. Licensed under the GPLv2 license.

0 commit comments

Comments
 (0)