-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
95 lines (89 loc) · 2.6 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
//注意事项:
/*
* 为避免污染全局变量,使用IIFE
* 只支持在modules下制作插件
* 为了防止插件之间的冲突,请确保modules文件夹下,制作的插件变量名和文件夹名称一致
*/
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
options: {
asi: true,
expr: true
},
src: ['Gruntfile.js', 'src/**/*.js']
},
watch: {
jshint: {
files: ['Gruntfile.js', 'src/**/*.js'],
tasks: ['jshint']
}
},
concat: {
js: {
src: '<%= concatJsSrc %>',
dest: '<%= concatJsDest %>'
},
css: {
src: '<%= concatCssSrc %>',
dest: '<%= concatCssDest %>'
}
},
uglify: {
all: {
src: 'dist/mho.all.js',
dest: 'dist/mho.all.min.js'
},
modules: {
src: 'dist/modules/mho.modules.js',
dest: 'dist/modules/mho.modules.min.js'
}
},
cssmin: {
all: {
src: 'dist/mho.all.css',
dest: 'dist/mho.all.min.css'
},
modules: {
src: 'dist/modules/mho.modules.css',
dest: 'dist/modules/mho.modules.min.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask('default', ['jshint', 'watch']);
//运行方式
//打包所有>grunt build
//打包制定插件>grunt build:form,table(被依赖插件写在前面)
grunt.registerTask('build', function(modules) {
var jsSrc = ['src/mho.js', 'src/modules/**/*.js'],
jsDest = 'dist/mho.all.js',
cssSrc = ['src/mho.css', 'src/modules/**/*.css'],
cssDest = 'dist/mho.all.css',
uglify = modules ? 'uglify:modules' : 'uglify:all';
cssmin = modules ? 'cssmin:modules' : 'cssmin:all';
if(modules) {
modules = modules.split(',');
jsSrc = ['src/mho.js'];
jsDest = 'dist/modules/mho.modules.js';
cssSrc = ['src/mho.css'];
cssDest = 'dist/modules/mho.modules.css';
for(var i=0; i<modules.length; i++) {
jsSrc.push('src/modules/'+modules[i]+'/*.js');
cssSrc.push('src/modules/'+modules[i]+'/*.css');
}
}
grunt.config.set('concatJsSrc', jsSrc);
grunt.config.set('concatJsDest', jsDest);
grunt.config.set('concatCssSrc', cssSrc);
grunt.config.set('concatCssDest', cssDest);
grunt.task.run('jshint');
grunt.task.run('concat');
grunt.task.run(uglify);
grunt.task.run(cssmin);
});
};