-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
79 lines (64 loc) · 2.05 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
module.exports = function(grunt){
// 显示任务时间
require("time-grunt")(grunt);
// 载入任务插件
require("load-grunt-tasks")(grunt);
// 项目配置
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
uglify: {
options: {
banner: "/*! <%= pkg.name %> <%= grunt.template.today(\"yyyy-mm-dd\") %> */\n"
},
build: {
src: "dist/<%=pkg.name %>.js",
dest: "dist/<%= pkg.name %>.min.js"
}
},
// js格式验证
jshint: {
all: {
src: [
"src/**/*.js", "Gruntfile.js"
],
options: {
jshintrc: true
}
}
},
// 合并文件
concat: {
options: {
// separator: ""
},
dist: {
src: ["src/intro.js", "src/core.js", "src/helper.js", "src/check.js", "src/outro.js",],
dest: "dist/<%=pkg.name %>.js"
},
},
// 自动验证编译
watch: {
jshint: {
files: ["src/**/*.js"],
tasks: ["concat", "compileBuild"]
}
}
});
// 默认任务
grunt.registerTask("default", ["concat", "compileBuild"]);
// 开发
grunt.registerTask("dev", ["default", "watch"]);
// 压缩
grunt.registerTask("dist", ["default", "uglify"]);
// 注册自定义替换任务
grunt.registerTask("compileBuild", "compile Build file.", function() {
var name = "./dist/loaded-check.js";
var file = grunt.file.read(name);
var version = grunt.file.readJSON("./package.json").version;
file = file.replace( /@VERSION/g, version )
// 替换时间
// yyyy-mm-ddThh:mmZ
.replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) );
grunt.file.write( name, file );
});
};