-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
172 lines (167 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// 确保代码中没有明显的错误
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'<%= pkg.appPath %>/**/*.js'
]
}
},
// 统一代码风格
jscs: {
options: {
config: '.jscsrc',
verbose: true
},
all: {
src: [
'Gruntfile.js',
'<%= pkg.appPath %>/**/*.js'
]
}
},
clean: {
options: {
force: true
},
dist: ['dist']
},
copy: {
index: {
expand: true,
cwd: 'src/',
src: 'index.html',
dest: 'dist'
},
login:{
expand: true,
cwd: 'src/',
src: 'login.html',
dest: 'dist'
},
assets: {
expand: true,
cwd: 'src/assets/',
src: '**/*',
dest: 'dist/assets/'
},
data: {
expand: true,
cwd: 'src/data/',
src: '**/*',
dest: 'dist/data/'
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
connect.static('src')
];
}
}
}
},
concat: {
options: {
//separator: ';'
},
allInOne: { //所有JS文件全部合并成一份文件
// src: ['src/js/**/*.js'],
// dest: 'dist/src-concated/js/<%= pkg.name %>.js'
}
},
uglify: {
options: {
// banner: '/*! <%= pkg.name %> <%= grunt.template.today('yyyy-mm-dd') %> */\n'
},
buildsrc: { //按照原来的目录结构压缩所有JS文件
options: {
mangle: false,
// {
// except: ['_', '$', 'jQuery', 'jquery','angular','$scope', '$element', '$attrs','$state','require','define','echarts']
// }
compress: {
drop_console: true
},
report: 'min' //输出压缩率,可选的值有 false(不输出信息),gzip
},
files: [{
expand: true,
cwd: '<%= pkg.appPath %>', //进入app目录
src: '**/*js', //压缩此目录下的所有文件
dest: 'dist/app' //输出到此目录下
}]
}
},
cssmin: {
css_all: {
expand: true,
cwd: '<%= pkg.appPath %>',
src: ['**/*css'],
dest: 'dist/app'
}
},
htmlmin: {
html_all: {
expand: true,
cwd: '<%= pkg.appPath %>',
src: ['**/*.html'],
dest: 'dist/app'
}
},
watch: {
js: {
files: ['src/**/*.js'],
tasks: ['uglify:buildsrc','jshint:all', 'jscs:all'],
options: {
spawn: true,
interrupt: true,
livereload: '<%= connect.options.livereload %>'
}
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'src/**/*'
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-jscs');
grunt.registerTask('serve', 'Compile then start a connect web server', function () {
grunt.task.run([
'connect:livereload',
'watch'
]);
});
grunt.registerTask('default', ['clean', 'uglify:buildsrc', 'cssmin', 'htmlmin', 'copy']);
};