-
Notifications
You must be signed in to change notification settings - Fork 173
/
Gruntfile.js
104 lines (102 loc) · 3.3 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
module.exports = function(grunt) {
var pkg = grunt.file.readJSON("package.json");
grunt.initConfig({
//如果需要用到 package.json 中的参数变量,可使用 pkg 引用(如 pkg.name)
pkg: pkg,
//监控自动编译
watch: {
livereload: {
options: {
livereload: "<%=connect.options.livereload%>" //监听前面声明的端口 28820
},
//监听文件列表
files: ["demo/**", "src/**", "test/**"]
}
},
connect: {
options: {
port: 8820, //webserver 端口
hostname: "*", //可配置为本机某个 IP,localhost 或域名
livereload: 28820 //声明给 watch 监听的端口
//protocol: 'https',
// key: grunt.file.read('server.key').toString(),
// cert: grunt.file.read('server.crt').toString(),
// ca: grunt.file.read('ca.crt').toString()
},
server: {
options: {
open: true, //自动打开网页 http://localhost:8820
base: [
//主目录
"./"
]
}
}
},
//eslint 代码质量检查任务
eslint: {
options: {},
src: ["src/bootstrap-suggest.js"]
},
//concat 多文件合并任务
concat: {
js: {
options: {
separator: "\n", //多文件分隔符,
// stripBanners: true,
process: function(src) {
return src.replace("VERSION_PLACEHOLDER", pkg.version);
}
},
src: ["src/bootstrap-suggest.js"], //合并哪些文件
dest: "dist/bootstrap-suggest.min.js" //合并后输出
}
},
//uglify 压缩任务,压缩 js
uglify: {
options: {
sourceMap: true,
compress: {
drop_console: true
},
banner:
"/**\r\n * <%= pkg.name %> - v<%= pkg.version %>\r\n" +
" * @description <%= pkg.description %>\r\n" +
" * @author <%= pkg.author.name %> - <%= pkg.author.url %>\r\n" +
" * @GitHub <%= pkg.repository.url %>\r\n" +
' * @since <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>\r\n' +
" */\r\n"
},
js: {
files: {
"dist/bootstrap-suggest.min.js": ["dist/bootstrap-suggest.min.js"] //替换保存
}
}
}
//cssmin 压缩任务,压缩 css
/*cssmin: {
css: {
src: 'src/index.css',
dest: 'dist/index.min.css'
}
},*/
//复制到发布目录
/*copy: {
main: {
src: 'dist/bootstrap-suggest.min.js',
dest: '../../resources/orion/lib/bootstrap-suggest-plugin/bootstrap-suggest.min.js',
},
}*/
});
//加载包含 concat 和 uglify 任务的插件
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-uglify");
//grunt.loadNpmTasks('grunt-contrib-copy');
//默认被执行的任务列表
grunt.registerTask("default", ["serve"]);
//自定义任务列表
grunt.registerTask("serve", ["connect:server", "watch"]);
grunt.registerTask("prod", [/*'eslint',*/ "concat", "uglify"]);
};