-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGruntfile.js
More file actions
166 lines (155 loc) · 4.74 KB
/
Gruntfile.js
File metadata and controls
166 lines (155 loc) · 4.74 KB
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
// Generated on 2014-12-11 using generator-angular 0.10.0
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
// Configurable paths for the application
var appConfig = {
app: 'src',
dist: 'dist',
demo: 'demo'
};
module.exports = function(grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
config: appConfig,
copy: {
dist: {
expand: true, // 当使用cwd时需要expand,动态src的映射
cwd: '<%= config.app %>/', // 相对于src,需要/
src: '*.js',
dest: '<%= config.dist %>/', // 需要/
ext: '.js', //是否修改目标文件的后缀名
}
},
clean: {
dist: {
src: '<%= config.dist %>/**/*',
dot: true,
expand: true
}
},
jshint: {
options: {
jshintrc: '.jshintrc',
force: true, // wont stop if hint failed
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'<%= config.app %>/{,*/}*.js'
]
}
},
uglify: {
dist: {
expand: true,
cwd: '<%= config.dist %>/',
src: '**/*.js',
dest: '<%= config.dist %>/',
ext: '.min.js'
}
},
// Automatically inject Bower components into the app
wiredep: {
demo: {
devDependencies: true,
src: ['<%= config.demo %>/index.html'],
ignorePath: /\.\.\//
}
},
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
gruntfile: {
files: ['Gruntfile.js']
},
less: {
files: ['<%= config.app %>/*.less'],
tasks: ['less:dist']
},
js: {
files: ['<%= config.app %>/*.js'],
tasks: ['copy:dist']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [ // 监听到文件变化不执行任何task,直接reload
'<%= config.demo %>/{,*/}*.{js,css,html}',
'<%= config.dist %>/{,*/}*.{js,css}'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9080,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: false, // 自动打开浏览器
middleware: function(connect) {
return [
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.demo),
connect.static(appConfig.dist)
];
}
}
},
dist: {
options: {
open: true,
base: '<%= config.demo %>'
}
}
},
// compile less to css
less : {
dist: {
files: [{
expand: true,
cwd: '<%= config.app %>/',
src: '*.less',
dest: '<%= config.dist %>/',
ext: '.css'
}]
}
}
});
grunt.registerTask('build', [
'clean',
'jshint',
'copy:dist',
'less:dist',
'uglify:dist'
]);
grunt.registerTask('serve', 'Compile then start a connect web server', function(target) {
if (grunt.option('local')) {
grunt.config.set('connect.options.hostname', 'localhost');
}
grunt.task.run([
'build',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('default', ['serve']);
};