Gruntfile.js
6.69 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
'use strict';
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Show grunt task time
require('time-grunt')(grunt);
// Configurable paths for the app
var appConfig = {
app: 'app',
dist: 'dist'
};
// Grunt configuration
grunt.initConfig({
// Project settings
inspinia: appConfig,
// The grunt server settings
connect: {
options: {
port: 9000,
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},
dist: {
options: {
open: true,
base: '<%= inspinia.dist %>'
}
}
},
// Compile less to css
less: {
development: {
options: {
compress: true,
optimization: 2
},
files: {
"app/styles/style.css": "app/less/style.less"
}
}
},
// Watch for changes in live edit
watch: {
styles: {
files: ['app/less/**/*.less'],
tasks: ['less', 'copy:styles'],
options: {
nospawn: true,
livereload: '<%= connect.options.livereload %>'
},
},
js: {
files: ['<%= inspinia.app %>/scripts/{,*/}*.js'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= inspinia.app %>/**/*.html',
'.tmp/styles/{,*/}*.css',
'<%= inspinia.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// If you want to turn on uglify you will need write your angular code with string-injection based syntax
// For example this is normal syntax: function exampleCtrl ($scope, $rootScope, $location, $http){}
// And string-injection based syntax is: ['$scope', '$rootScope', '$location', '$http', function exampleCtrl ($scope, $rootScope, $location, $http){}]
uglify: {
options: {
mangle: false
}
},
// Clean dist folder
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= inspinia.dist %>/{,*/}*',
'!<%= inspinia.dist %>/.git*'
]
}]
},
server: '.tmp'
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [
{
expand: true,
dot: true,
cwd: '<%= inspinia.app %>',
dest: '<%= inspinia.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'*.html',
'views/{,*/}*.html',
'styles/patterns/*.*',
'img/{,*/}*.*'
]
},
{
expand: true,
dot: true,
cwd: 'bower_components/fontawesome',
src: ['fonts/*.*'],
dest: '<%= inspinia.dist %>'
},
{
expand: true,
dot: true,
cwd: 'bower_components/bootstrap',
src: ['fonts/*.*'],
dest: '<%= inspinia.dist %>'
},
]
},
styles: {
expand: true,
cwd: '<%= inspinia.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'<%= inspinia.dist %>/scripts/{,*/}*.js',
'<%= inspinia.dist %>/styles/{,*/}*.css',
'<%= inspinia.dist %>/styles/fonts/*'
]
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= inspinia.dist %>',
src: ['*.html', 'views/{,*/}*.html'],
dest: '<%= inspinia.dist %>'
}]
}
},
useminPrepare: {
html: 'app/index.html',
options: {
dest: 'dist'
}
},
usemin: {
html: ['dist/index.html']
}
});
// Run live version of app
grunt.registerTask('live', [
'clean:server',
'copy:styles',
'connect:livereload',
'watch'
]);
// Run build version of app
grunt.registerTask('server', [
'build',
'connect:dist:keepalive'
]);
// Build version for production
grunt.registerTask('build', [
'clean:dist',
'less',
'useminPrepare',
'concat',
'copy:dist',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
};