-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
146 lines (128 loc) · 4.92 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
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
var production = !!grunt.option('production');
var pkg = grunt.file.readJSON('package.json');
// setting browser compatibility
if (typeof (pkg.supportedBrowsers) == 'undefined') {
pkg.supportedBrowsers = ['> 5% in DE', 'ie 10'];
}
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
default: {
options: {
compress: production,
yuicompress: production,
optimization: 2,
sourceMap: !production,
sourceMapURL: 'styles.css.map',
plugins: [
new (require('less-plugin-autoprefix'))({browsers: pkg.supportedBrowsers})
]
},
files: [{
expand: true, // Enable dynamic expansion.
cwd: './', // Src matches are relative to this path.
src: ['**/less/be.less', '**/less/fe.less'], // Actual pattern(s) to match.
dest: './', // Destination path prefix.
ext: '.css', // Dest filepaths will have this extension.
extDot: 'last', // Extensions in filenames begin after the first dot
rename: function (dest, src) {
src = src.replace(/\/less\//, '/../assets/css/');
return src;
}
}],
}
},
concat: {
options: {
separator: ';\n',
stripBanners: production,
sourceMap: !production
}
},
uglify: {
options: {
sourceMap: !production,
sourceMapIncludeSources: !production,
sourceMapIn: function (path) {
return path.replace(/\.js/, "\.js\.map")
},
compress: {
drop_console: production
}
}
},
shell: {
default: {
command: './rsync.sh'
}
},
watch: {
css: {
files: ['**/less/**/*.less'], // which files to watch
tasks: ['less:default', 'shell:default']
},
rsync: {
files: ['**/assets/**/*'],
tasks: ['shell:default']
}
}
});
// get all module directories
grunt.file.expand('**/assets_src/js/be').forEach(function (dir) {
// get the module name from the directory name
var dirName = dir.substr(dir.lastIndexOf('/') + 1),
taskLabel = dir.replace(/[^a-zA-Z0-9\_]/g, '_');
// get the current concat object from initConfig
var concat = grunt.config.get('concat') || {};
concat[taskLabel] = {
src: [dir + '/**/*.js'],
dest: dir + '/../../../assets/js/be.js'
};
grunt.config.set('concat', concat);
var uglify = grunt.config.get('uglify') || {};
uglify[taskLabel] = {
src: ['<%= concat.' + taskLabel + '.dest %>'],
dest: '<%= concat.' + taskLabel + '.dest %>'
};
grunt.config.set('uglify', uglify);
var watch = grunt.config.get('watch') || {};
watch[taskLabel] = {
files: ['<%= concat.' + taskLabel + '.src %>'],
tasks: ['concat:' + taskLabel, 'uglify:' + taskLabel, 'shell:default']
};
grunt.config.set('watch', watch);
});
// get all module directories
grunt.file.expand('**/assets_src/js/fe').forEach(function (dir) {
// get the module name from the directory name
var dirName = dir.substr(dir.lastIndexOf('/') + 1),
taskLabel = dir.replace(/[^a-zA-Z0-9\_]/g, '_');
// get the current concat object from initConfig
var concat = grunt.config.get('concat') || {};
concat[taskLabel] = {
src: [dir + '/**/*.js'],
dest: dir + '/../../../assets/js/fe.js'
};
grunt.config.set('concat', concat);
var uglify = grunt.config.get('uglify') || {};
uglify[taskLabel] = {
src: ['<%= concat.' + taskLabel + '.dest %>'],
dest: '<%= concat.' + taskLabel + '.dest %>'
};
grunt.config.set('uglify', uglify);
var watch = grunt.config.get('watch') || {};
watch[taskLabel] = {
files: ['<%= concat.' + taskLabel + '.src %>'],
tasks: ['concat:' + taskLabel, 'uglify:' + taskLabel, 'shell:default']
};
grunt.config.set('watch', watch);
});
if (production) {
grunt.registerTask('default', ['concat', 'uglify', 'less', 'shell']);
} else {
grunt.registerTask('default', ['concat', 'less', 'shell', 'watch']);
}
};