Skip to content

Commit cc3b08d

Browse files
committed
Build/grunt: Minify CSS files, using sqwish.
1 parent 02981c7 commit cc3b08d

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

grunt.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/*global config:true, task:true*/
22
var coreFiles = 'jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.effects.core.js'.split(', ');
3-
var allFiles = coreFiles.map(function(file) {
3+
var uiFiles = coreFiles.map(function(file) {
44
return 'ui/' + file;
55
}).concat(file.expand('ui/*.js').filter(function(file) {
66
return coreFiles.indexOf(file.substring(3)) === -1;
77
}));
8-
var rawList = allFiles.map(function(file) {
9-
return file.substring(3);
10-
});
118

129
var minify = {
1310
'dist/ui/minified/jquery-ui.min.js': ['<banner:meta.bannerAll>', 'dist/ui/jquery-ui.js'],
@@ -16,19 +13,23 @@ var minify = {
1613
function minFile(file) {
1714
minify['dist/' + file.replace(/\.js$/, '.min.js').replace(/ui\//, 'ui/minified/')] = ['<banner>', file];
1815
}
19-
allFiles.forEach(minFile);
16+
uiFiles.forEach(minFile);
2017

2118
var allI18nFiles = file.expand('ui/i18n/*.js');
2219
allI18nFiles.forEach(minFile);
23-
var i18nfiles = allI18nFiles.map(function(file) {
24-
return file.substring(8);
25-
});
20+
21+
// TODO move core to the front, theme to the end, exclude all and base
22+
var cssFiles = file.expand('themes/base/*.css');
2623

2724
function createBanner(files) {
25+
// strip folders
26+
var fileNames = files && files.map(function(file) {
27+
return file.replace(/.+\/(.+)$/, '$1');
28+
});
2829
return '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
2930
'<%= template.today("isoDate") %>\n' +
3031
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
31-
(files ? '* Includes: ' + files.join(', ') + '\n' : '') +
32+
(files ? '* Includes: ' + fileNames.join(', ') + '\n' : '') +
3233
'* Copyright (c) <%= template.today("yyyy") %> <%= pkg.author.name %>;' +
3334
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */';
3435
}
@@ -37,14 +38,21 @@ config.init({
3738
pkg: '<json:package.json>',
3839
meta: {
3940
banner: createBanner(),
40-
bannerAll: createBanner(rawList),
41-
bannerI18n: createBanner(i18nfiles)
41+
bannerAll: createBanner(uiFiles),
42+
bannerI18n: createBanner(allI18nFiles),
43+
bannerCSS: createBanner(cssFiles)
4244
},
4345
concat: {
44-
'dist/ui/jquery-ui.js': allFiles,
46+
'dist/ui/jquery-ui.js': uiFiles,
4547
'dist/ui/i18n/jquery-ui-i18n.js': 'ui/i18n/*.js'
4648
},
4749
min: minify,
50+
css_min: {
51+
dist: {
52+
src: ['<banner:meta.bannerCSS>'].concat(cssFiles),
53+
dest: 'dist/themes/base/minified/jquery-ui.min.css'
54+
}
55+
},
4856
zip: {
4957
dist: {
5058
src: [
@@ -107,5 +115,26 @@ task.registerBasicTask('zip', 'Create a zip file for release', function(data) {
107115
log.writeln("Wrote " + files.length + " files to " + data.dest);
108116
});
109117

118+
task.registerBasicTask( 'css_min', 'Minify CSS files with Sqwish.', function( data ) {
119+
var files = file.expand( data.src );
120+
// Get banner, if specified. It would be nice if UglifyJS supported ignoring
121+
// all comments matching a certain pattern, like /*!...*/, but it doesn't.
122+
var banner = task.directive(files[0], function() { return null; });
123+
if (banner === null) {
124+
banner = '';
125+
} else {
126+
files.shift();
127+
}
128+
var max = task.helper( 'concat', files );
129+
// Concat banner + minified source.
130+
var min = banner + require('sqwish').minify( max, false );
131+
file.write( data.dest, min );
132+
if ( task.hadErrors() ) {
133+
return false;
134+
}
135+
log.writeln( 'File "' + data.dest + '" created.' );
136+
task.helper( 'min_max_info', min, max );
137+
});
138+
110139
task.registerTask('default', 'lint qunit');
111140
task.registerTask('release', 'concat min zip');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"dependencies": {},
2828
"devDependencies": {
2929
"grunt": "0.2.x",
30-
"adm-zip": "0.1.x"
30+
"adm-zip": "0.1.x",
31+
"sqwish": "0.2.x"
3132
},
3233
"keywords": []
3334
}

0 commit comments

Comments
 (0)