Skip to content

Commit f6cfdd3

Browse files
committed
use grunt-css plugin
1 parent 30c4e91 commit f6cfdd3

File tree

3 files changed

+42
-54
lines changed

3 files changed

+42
-54
lines changed

build/tasks/css.js

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var requirejs = require( 'requirejs' ),
66

77
module.exports = function( grunt ) {
88
var config = grunt.config.get( 'global' ),
9+
cssmin = {},
910
regularFile = path.join( config.dirs.output, config.names.root ),
1011
structureFile = path.join( config.dirs.output, config.names.structure ),
1112
themeFile = path.join( config.dirs.output, config.names.theme ),
@@ -29,67 +30,50 @@ module.exports = function( grunt ) {
2930
}
3031
});
3132

32-
grunt.registerTask( 'css_without_deps', 'compile and minify the css', function() {
33-
var done = this.async(),
34-
theme = grunt.config.get( 'css' ).theme,
35-
require = grunt.config.get( 'css' ).require,
36-
global_config = grunt.config.get( 'global' );
37-
38-
// pull the includes together using require js
39-
requirejs.optimize( require.all );
33+
grunt.config.set( 'concat', {
34+
structure: {
35+
src: [ '<banner:global.ver.header>', structureFile + '.compiled.css' ],
36+
dest: structureFile + '.css'
37+
},
38+
39+
regular: {
40+
src: [ '<banner:global.ver.header>', regularFile + '.compiled.css' ],
41+
dest: regularFile + '.css'
42+
},
43+
44+
theme: {
45+
src: [
46+
'<banner:global.ver.header>',
47+
'css/themes/default/jquery.mobile.theme.css'
48+
],
49+
dest: themeFile + '.css'
50+
}
51+
});
4052

41-
// dump the versioned header into the normal css file
42-
grunt.file.write( regularFile + '.css', global_config.ver.header );
53+
// setup css min configuration
54+
cssmin[ regularFile + '.min.css' ] = [ "<banner:global.ver.min>", regularFile + '.css' ];
55+
cssmin[ structureFile + '.min.css' ] = [ "<banner:global.ver.min>", structureFile + '.css' ];
56+
cssmin[ themeFile + '.min.css' ] = [ "<banner:global.ver.min>", themeFile + '.css' ];
57+
grunt.config.set( 'cssmin', cssmin );
4358

44-
// add the compiled css to the normal css file
45-
helpers.appendFrom( regularFile + '.css', require.all.out );
59+
grunt.registerTask( 'css_compile', 'use require js to sort out deps', function() {
60+
var require = grunt.config.get( 'css' ).require;
4661

47-
helpers.minify({
48-
output: regularFile + '.min.css',
49-
input: regularFile + '.css',
50-
header: global_config.ver.min,
51-
minCallback: function( unminified ) {
52-
return sqwish.minify( unminified, false );
53-
}
54-
});
62+
// pull the includes together using require js
63+
requirejs.optimize( require.all );
5564

5665
// pull the includes together using require js
5766
requirejs.optimize( require.structure );
5867

59-
// dump the versioned header into the structure css file
60-
grunt.file.write( structureFile + '.css', global_config.ver.header );
61-
62-
// add the compiled structure css to the normal css file
63-
helpers.appendFrom( structureFile + '.css', require.structure.out );
64-
65-
// add the min header into the minified file
66-
grunt.file.write( structureFile + '.min.css', global_config.ver.min );
67-
68-
// minify the structure css
69-
helpers.minify({
70-
output: structureFile + '.min.css',
71-
input: structureFile + '.css',
72-
header: global_config.ver.min,
73-
minCallback: function( unminified ) {
74-
return sqwish.minify( unminified, false );
75-
}
76-
});
77-
78-
// dump the versioned header into the theme css file
79-
grunt.file.write( themeFile + '.css', global_config.ver.header );
80-
81-
// dump the theme css into the theme css file
82-
helpers.appendFrom( themeFile + '.css', 'css/themes/default/jquery.mobile.theme.css' );
68+
// simple theme file compile
69+
grunt.file.write( themeFile + '.css', 'css/themes/default/jquery.mobile.theme.css' );
70+
});
8371

84-
// minify the theme css
85-
helpers.minify({
86-
output: themeFile + '.min.css',
87-
input: themeFile + '.css',
88-
header: global_config.ver.min,
89-
minCallback: function( unminified ) {
90-
return sqwish.minify( unminified, false );
91-
}
92-
});
72+
grunt.registerTask( 'css_cleanup', 'compile and minify the css', function() {
73+
var done = this.async(),
74+
theme = grunt.config.get( 'css' ).theme,
75+
require = grunt.config.get( 'css' ).require,
76+
global_config = grunt.config.get( 'global' );
9377

9478
// remove the requirejs compile output
9579
fs.unlink( require.all.out );
@@ -111,5 +95,5 @@ module.exports = function( grunt ) {
11195
});
11296
});
11397

114-
grunt.registerTask( 'css', 'async_config custom_init css_without_deps' );
98+
grunt.registerTask( 'css', 'custom_init async_config css_compile concat:regular concat:structure concat:theme cssmin css_cleanup' );
11599
};

grunt.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ module.exports = function( grunt ) {
4848
// set the default task.
4949
grunt.registerTask('default', 'lint');
5050

51+
// csslint and cssmin tasks
52+
grunt.loadNpmTasks( "grunt-css" );
53+
5154
// A convenient task alias.
5255
grunt.registerTask('test', 'test_config qunit');
5356

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"grunt": "0.3.x",
15+
"grunt-css": "0.2.0",
1516
"requirejs": "1.0.8",
1617
"sqwish": "0.2.0",
1718
"glob-whatev": "~0.1.4"

0 commit comments

Comments
 (0)