-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
148 lines (133 loc) · 4.76 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
module.exports = function (grunt) {
//js libs root path
var jsLibSrcPath = 'src/main/webapp/resources/lib';
var jsLibDstPath = 'src/main/webapp/resources/release/js';
var destLibJsName = 'libs.js', destLibJsMinName = 'libs.min.js';
//js angular-app root path
var jsAppSrcPath = 'src/main/webapp/resources/dev/js/angular-app';
var jsAppDstPath = 'src/main/webapp/resources/release/js';
var destAppJsName = 'angular-app.js', destAppJsMinName = 'angular-app.min.js';
//css root path
var cssLibSrcPath = 'src/main/webapp/resources/lib/css';
var cssLibDstPath = 'src/main/webapp/resources/release/css';
var destLibCssName = 'styles.css', destLibCssMinName = 'styles.min.css';
//css custom styles path
var cssCustomSrcPath = 'src/main/webapp/resources/dev/css';
//libs files to concat
var jsLibFilesPath = [
//jquery first
jsLibSrcPath + '/jquery.min.js',
jsLibSrcPath + '/bootstrap.min.js',
jsLibSrcPath + '/angular.min.js',
jsLibSrcPath + '/dependencies/*.js'
];
//app files to concat
var jsAppFilesPath = [
jsAppSrcPath + '/**/*.js'
//jsAppSrcPath + '/',
];
//css files to concat
var cssFilesPath = [
cssLibSrcPath + '/*.css',
cssCustomSrcPath + '/custom.css',
cssLibSrcPath + '/custom.css'
];
//------------------------------------------------------------
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//------------------------------------------------------------
//----- concat begin -----
concat: {
js: {
options: {
separator: ';\n'
},
files: [
//js lib files
{
src: jsLibFilesPath,
dest: jsLibDstPath + '/' + destLibJsName
},
//js angular-app files
{
src: jsAppFilesPath,
dest: jsAppDstPath + '/' + destAppJsName
}
]
}
},
//----- concat end -----
//----- uglify begin -----
uglify: { // Task uglify
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
mangle: {
except: ['jquery.min.js', 'bootstrap.min.js', 'angular.min.js']
},
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
}
},
js: { // Target
files: [
//js lib files
{
src: [jsLibDstPath + '/' + destLibJsName],
dest: jsLibDstPath + '/' + destLibJsMinName
},
//js angular-app files
{
src: [jsAppDstPath + '/' + destAppJsName],
dest: jsAppDstPath + '/' + destAppJsMinName
}
]
}
},
//----- uglify end -----
//----- cssmin begin -----
cssmin: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
},
concat_css: {
files: [
{
src: cssFilesPath,
dest: cssLibDstPath + '/' + destLibCssName
}
]
},
minify_css: {
files: [
{
src: [cssLibDstPath + '/' + destLibCssName],
dest: cssLibDstPath + '/' + destLibCssMinName
}
]
}
}
//----- cssmin end -----
});
//init plugins
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
//register tasks
//js
grunt.registerTask('concat-js', ['concat:js']);
grunt.registerTask('minify-js', ['uglify:js']);
grunt.registerTask('process-all-js', ['concat-js', 'minify-js']);
//css
grunt.registerTask('concat-css', ['cssmin:concat_css']);
grunt.registerTask('minify-css', ['cssmin:minify_css']);
grunt.registerTask('process-all-css', ['concat-css', 'minify-css']);
//final task
grunt.registerTask('compress-all', ['process-all-js', 'process-all-css']);
};