This repository has been archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gruntfile.js
150 lines (139 loc) · 4.72 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
150
module.exports = function (grunt) { // NOSONAR
var path = require('path');
var targetDir = 'target';
var pageDir = 'emails';
var tmpDir = targetDir + '/.tmp';
var pageTmpDir = tmpDir + '/emails';
var pageTmpPath = pageTmpDir + '/index.html';
var pageTargetPath = targetDir + '/index.html';
// Helper
var helper = {
createConfig: function (context, block) {
var cfg = { files: [] };
var outfile = path.join(context.outDir, block.dest);
var filesDef = {};
filesDef.dest = outfile;
filesDef.src = [];
context.inFiles.forEach(function (inFile) {
filesDef.src.push(path.join(context.inDir, inFile));
});
cfg.files.push(filesDef);
context.outFiles = [block.dest];
return cfg;
}
};
// Measures the time each task takes
require('time-grunt')(grunt);
// Tasks
grunt.initConfig({
less: {
generated: {}
},
concat: {
generated: {}
},
copy: {
tmp: {
files: [{
expand: true,
cwd: pageDir,
src: '*.html',
dest: pageTmpDir
}]
}
},
useminPrepare: {
index: pageTmpPath,
options: {
dest: pageTmpDir,
root: pageDir,
staging: tmpDir,
flow: {
steps: {
css: ['concat'],
less: [{
name: 'less',
'createConfig': function (context, block) {
return helper.createConfig(context, block);
}
}]
},
post: {}
}
}
},
usemin: {
index: pageTmpPath,
options: {
blockReplacements: {
less: function (block) {
return '<link rel="stylesheet" href="' + block.dest + '">';
}
}
}
},
clean: {
target: targetDir
},
inlinecss: {
options: {
xmlMode: false,
applyWidthAttributes: true,
applyHeightAttributes: true,
applyAttributesTableElements: true,
preserveImportant: true,
preserveMediaQueries: true,
preserveFontFaces: true,
insertPreservedExtraCss: false,
webResources: {
images: false
}
},
index: {
src: pageTmpPath,
dest: pageTargetPath
}
},
postcss: {
options: {
processors: [
// https://github.com/postcss/autoprefixer
require('autoprefixer')({
// ie >= 8; https://github.com/ai/browserslist
browsers: ["last 2 versions", "> 1%"]
}),
// http://cssnano.co
require('cssnano')({
// Disable unsafe optimizations
reduceIdents: false,
zindex: false,
mergeIdents: false,
discardUnused: false
})
]
},
index: {
src: pageTmpDir + '/css/master.css',
dest: pageTmpDir + '/css/master.css'
}
}
});
// Load grunt plugins installed using npm install
grunt.loadNpmTasks('grunt-contrib-clean'); // https://github.com/gruntjs/grunt-contrib-clean
grunt.loadNpmTasks('grunt-contrib-concat'); // https://github.com/gruntjs/grunt-contrib-concat
grunt.loadNpmTasks('grunt-contrib-copy'); // https://github.com/gruntjs/grunt-contrib-copy
grunt.loadNpmTasks('grunt-contrib-less'); // https://github.com/gruntjs/grunt-contrib-less
grunt.loadNpmTasks('grunt-inline-css'); // https://github.com/jgallen23/grunt-inline-css
grunt.loadNpmTasks('grunt-postcss'); // https://github.com/nDmitry/grunt-postcss
grunt.loadNpmTasks('grunt-usemin'); // https://github.com/yeoman/grunt-usemin
grunt.registerTask('emails:build', [
'clean:target',
'copy:tmp',
'useminPrepare:index',
'less:generated',
'concat:generated',
'usemin:index',
'postcss:index',
'inlinecss:index'
]);
};