-
Notifications
You must be signed in to change notification settings - Fork 152
/
Gruntfile.js
172 lines (154 loc) · 4.02 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
/webapp/assets -> before build
-> /grunt-ignore -> assets that will just be copied to production without any modifications (modify them freely)
-> /js -> js at development (modify them freely)
-> /less -> less (modify them freely)
-> /generated-css -> css processed from less + ignored css (these are generated automatically, please don't touch them)
/webapp/{css/js/imgs/font} -> after all the build, production assets (these are generated automatically, please don't touch them)
*/
module.exports = function(grunt) {
var config = {
generatedCss: 'src/main/webapp/assets/generated-css/',
assets: 'src/main/webapp/assets/',
webapp: 'src/main/webapp/',
ignored: 'src/main/webapp/assets/grunt-ignore/'
};
grunt.initConfig({
config: config,
clean: {
before: ["<%= config.webapp %>/{css,js,imgs,font}/"],
after: ["<%= config.assets %>"]
},
less: {
main: {
files:[{
expand: true,
cwd: '<%= config.assets %>/less',
src: ['**/*.less'],
dest: '<%= config.generatedCss %>',
ext: '.css'
}]
}
},
copy: {
ignored: {
files: [
{
expand: true,
cwd: '<%= config.ignored %>/js/',
src: ['**'],
dest: '<%= config.webapp %>/js/'
},
{
expand: true,
cwd: '<%= config.ignored %>/css/',
src: ['**'],
dest: '<%= config.webapp %>/css/'
},
{
expand: true,
cwd: '<%= config.ignored %>/font/',
src: ['**'],
dest: '<%= config.webapp %>/font/'
},
{
expand: true,
cwd: '<%= config.ignored %>/imgs/',
src: ['**'],
dest: '<%= config.webapp %>/imgs/',
}
]
},
special:{
files:[
{
expand: true,
cwd: '<%= config.webapp %>/imgs',
src: ['**'],
dest: '<%= config.webapp %>/css/imgs'
},
{
expand: true,
cwd: '<%= config.webapp %>/imgs',
src: ['**'],
dest: '<%= config.webapp %>/assets/imgs'
}
]
}
},
useminPrepare: {
html: '<%= config.webapp %>/WEB-INF/{jsp,tags}/**/*.{jsp,jspf,tag}',
options: {
root: '<%= config.webapp %>',
dest: '<%= config.webapp %>'
}
},
filerev: {
options: {
encoding: 'utf8',
algorithm: 'md5',
length: 8
},
source: {
files: [
{src: ['<%= config.webapp %>/js/**/*.js']},
{src: ['<%= config.webapp %>/css/**/*.css']}
]
}
},
usemin: {
html: ['<%= config.webapp %>/WEB-INF/{jsp,tags}/**/*.{jsp,jspf,tag}'],
options: {
dirs: ['<%= config.webapp %>'],
assetsDirs: ['<%= config.webapp %>'],
blockReplacements: {
css: function (block) {
return '<link rel="stylesheet" href="${contextPath}' + block.dest + '"/>';
},
js: function (block) {
return '<script src="${contextPath}' + block.dest + '"></script>';
}
}
}
},
watch: {
less: {
files: ['<%= config.assets %>/less/**/*.less'],
tasks: ['less'],
options: {
spawn: false
}
}
}
});
//remaps the filerev data to match the prefixed filenames
grunt.registerTask('remapFilerev', function(){
var root = grunt.config().config.webapp;
var summary = grunt.filerev.summary;
var fixed = {};
for(key in summary){
if(summary.hasOwnProperty(key)){
var orig = key.replace(root, root+'${contextPath}/');
var revved = summary[key].replace(root, root+'${contextPath}/');
fixed[orig] = revved;
}
}
grunt.filerev.summary = fixed;
});
['contrib-clean',
'contrib-less',
'contrib-watch',
'contrib-concat',
'contrib-cssmin',
'contrib-uglify',
'contrib-copy',
'filerev',
'usemin'
].forEach(function(plugin) {
grunt.loadNpmTasks('grunt-' + plugin);
});
grunt.registerTask('default', ['clean:before', 'less', 'copy:ignored']);
grunt.registerTask('build', ['default', 'useminPrepare', 'concat:generated', 'cssmin:generated',
'uglify', 'filerev', 'remapFilerev', 'usemin', 'clean:after']);
grunt.registerTask('run', ['default', 'copy:special', 'watch']);
};