forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
149 lines (135 loc) · 3.77 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
module.exports = function(grunt) {
grunt.initConfig({
responsive_images: {
//Resolution-Switching Cases here
resolution_switch_case: {
options: {
engine: 'im',
sizes: [{
/* Change these */
width: 1600,
suffix: '_large_2x',
quality: 30
},
{ width: 800,
suffix: '_large_1x',
quality: 30
},
{ width: 1280,
suffix: '_medium_2x',
quality: 30
},
{ width: 640,
suffix: '_medium_1x',
quality: 30
},
{ width: 640,
suffix: '_small_2x',
quality: 30
},
{ width: 320,
suffix: '_small_1x',
quality: 30
}]
},
/*
You don't need to change this part if you don't change
the directory structure.
*/
files: [{
expand: true,
src: ['*.{gif,jpg,png}'],
cwd: 'images_src/',
dest: 'img/'
}]
},
// Handling Art-Direction Cases here :)
large_art_direction: {
options: {
sizes: [{ width: 1600, suffix: '_large_2x', quality: 30}, {width: 800, suffix: 'large_1x', quality: 30}]
},
files: [{
expand: true,
//src: ['**/large_*.{jpg,gif,png}'], //Selects all files that begins with 'large_'
cwd: 'images_src/art_direction',
dest: 'img/'
}]
},
medium_art_direction: {
options: {
sizes: [{ width: 1280, suffix: '_medium_2x', quality: 30}, {width: 640, suffix: 'medium_1x', quality: 30}]
},
files: [{
expand: true,
//src: ['**/medium_*.{jpg,gif,png}'], //Selects all files that begins with 'medium_'
cwd: 'images_src/art_direction',
dest: 'img/'
}]
},
small_art_direction: {
options: {
sizes: [{ width: 640, suffix: '_small_2x', quality: 30}, {width: 320, suffix: 'small_1x', quality: 30}]
},
files: [{
expand: true,
src: ['**/*.{jpg,gif,png}'], //Selects all files
cwd: 'images_src/art_direction',
dest: 'img/'
}]
},
},
// WebP configuration - this convert all images in images/ folder to webp
// Make sure 'grunt-responsive-image' is run before 'grunt-webp' otherwise images in images/ foler will not be converted (as source for webp plugin is images/ folder)
webp: {
files: {
expand: true,
src: ['*.{gif,jpg,png}'],
cwd: 'img/',
dest: 'img/'
},
options: {
binpath: require('webp-bin').path,
preset: 'photo',
verbose: true,
quality: 80,
alphaQuality: 80,
compressionMethod: 6,
segments: 4,
psnr: 42,
sns: 50,
filterStrength: 40,
filterSharpness: 3,
simpleFilter: true,
partitionLimit: 50,
analysisPass: 6,
multiThreading: true,
lowMemory: false,
alphaMethod: 0,
alphaFilter: 'best',
alphaCleanup: true,
noAlpha: false,
lossless: false
}
},
/* Clear out the images directory if it exists */
clean: {
dev: {
src: ['img'],
},
},
/* Generate the images directory if it is missing */
mkdir: {
dev: {
options: {
create: ['img']
},
},
},
});
grunt.loadNpmTasks('grunt-responsive-images');
grunt.loadNpmTasks('grunt-webp');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-mkdir');
grunt.registerTask('default', ['clean', 'mkdir', 'responsive_images', 'webp']);
};