This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
/
Gruntfile.js
83 lines (73 loc) · 1.98 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
report: 'gzip'
},
build: {
files: {
'build/<%= pkg.name %>.min.js': 'src/app-promo.js'
}
}
},
stylusImages: {
options: {
baseDir: 'src',
imports: ['import/global']
},
mdpi: {
files: {
'build/<%= pkg.name %>.css': ['src/app-promo.styl']
}
},
hdpi: {
options: { resolution: '2' },
files: {
'build/<%= pkg.name %>@2x.css': ['src/app-promo.styl']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerMultiTask('stylusImages', function() {
var self = this,
options = this.options({
urlSizeLimit: 1500,
resolution: '1'
});
function compile(stylusCode, destFile, callback) {
var stylusImages = require('stylus-images'),
compiler = stylusImages(stylusCode, {
paths: [options.baseDir],
images: {
limit: options.urlSizeLimit,
resolutions: [options.resolution]
}
});
compiler.set('compress', true);
compiler.use(require('nib')());
compiler.import('nib');
options.imports.forEach(function(stylesheet) {
compiler.import(stylesheet);
});
compiler.render(function(err, data) {
if (err) {
grunt.log.writeln(err);
callback(false);
} else {
grunt.file.write(destFile, data[options.resolution]);
callback();
}
});
}
grunt.util.async.forEachSeries(this.files, function(file, next) {
var stylusCode = '';
file.src.forEach(function(fileName) {
stylusCode += '\n' + grunt.file.read(fileName);
});
compile(stylusCode, file.dest, next);
});
});
grunt.registerTask('default', ['uglify', 'stylusImages:hdpi']);
};