-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
130 lines (114 loc) · 2.93 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
/* global module, require, console */
var httpProxy = require('http-proxy');
module.exports = function (grunt){
'use strict';
require('time-grunt')(grunt);
require('jit-grunt')(grunt);
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist',
proxy: {
host: 'deis.local3.deisapp.com'
}
};
grunt.initConfig({
app: appConfig,
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: ['<%= app.app %>/scripts/**/*.js'],
tasks: ['newer:jshint:all'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= app.app %>/**/*.html'
]
}
},
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
middleware: function(connect) {
return [
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app),
connect.compress({
// Pass to connect.compress() the options
// that you need, just for show the example
// we use threshold to 1
threshold: 1
}),
connect().use(
'/api',
(function () {
var proxy = httpProxy.createProxyServer({});
proxy.on('error', function (err, req, res) {
console.error(err);
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.write('Error: ' + err.code);
res.end();
});
return function (req, res) {
delete req.headers['accept-encoding'];
req.headers.host = appConfig.proxy.host;
proxy.web(req, res, {
target: 'http://' + appConfig.proxy.host
});
};
})()
)
];
}
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'<%= app.app %>/scripts/**/*.js'
]
},
clean: {
server: '.tmp'
}
},
wiredep: {
app: {
src: ['<%= app.app %>/index.html'],
ignorePath: /\.\.\//
}
}
});
grunt.registerTask('serve', 'Compile and lauch a connect web server', function(){
grunt.task.run([
'wiredep',
'connect:livereload',
'watch'
]);
});
};