This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gruntfile.js
208 lines (178 loc) · 6.47 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
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
module.exports = function (grunt) {
'use strict';
// Load Grunt tasks automatically
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
grunt.initConfig({
// ---------------------------------------------------------------------
// | Project Settings |
// ---------------------------------------------------------------------
settings: {
// Configurable paths
dir: {
src: 'src',
dist: 'dist'
}
},
// ---------------------------------------------------------------------
// | Tasks Configurations |
// ---------------------------------------------------------------------
clean: {
// List of files that will be removed before the
// build process is started
all: [
'.tmp', // used by the `usemin` task
'<%= settings.dir.dist %>'
],
// List of files no longer required after the build
// process is completed
tmp: [
'.tmp' // used by the `usemin` task
]
},
connect: {
options: {
hostname: 'localhost', // → Change this to '0.0.0.0' if
// the server needs to be access
// from outside of the LAN
livereload: 35729,
port: 8080 // → 8080 is used as it is the official
// alternate to port 80 (default port
// for HTTP), and it doesn't require
// root access:
// https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
},
livereload: {
options: {
base: '<%= settings.dir.src %>',
// Automatically open the webpage in the default browser
open: true
}
}
},
copy: {
files: {
cwd: '<%= settings.dir.src %>/',
dest: '<%= settings.dir.dist %>/',
dot: true,
expand: true,
src: [
// copy all files
'**',
// except: files from the `css/` and `js/` directory
// (other tasks will handle the copying of these files)
'!css/*'
]
}
},
filerev: {
files: {
src: [
'<%= settings.dir.dist %>/js/*.js',
'<%= settings.dir.dist %>/css/*.css',
'!<%= settings.dir.dist %>/js/jquery*.min.js'
]
},
options: {
algorithm: 'sha1',
length: 7
}
},
jshint: {
files: [
'Gruntfile.js',
'<%= settings.dir.src %>/js/*.js',
'!<%= settings.dir.src %>/js/*.min.js'
],
options: {
// Search for `.jshintrc` files relative to files being linted
jshintrc: true,
// List of files that will be ignored by the linter
ignores: [
'<%= settings.dir.src %>/js/html5shiv.js'
]
}
},
htmlmin: {
build: {
files: {
'<%= settings.dir.dist %>/index.html': '<%= settings.dir.dist %>/index.html'
// DO NOT minify the 404 page! (the page needs to have more
// than 512 bytes in order for IE to display it)
// http://www.404-error-page.com/404-error-page-too-short-problem-microsoft-ie.shtml
},
// HTML minifier options in-depth explanation:
// http://perfectionkills.com/experimenting-with-html-minifier/#options
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true
}
}
},
uglify: {
options: {
// Preserve all comments that start with a bang (!) or include a
// closure compiler style directive (@preserve @license @cc_on)
preserveComments: 'some'
}
},
usemin: {
// List of files for which to update asset references
css: '<%= settings.dir.dist %>/css/*.css',
html: '<%= settings.dir.dist %>/index.html'
},
useminPrepare: {
// List of HTML files from which to process the usemin blocks
// https://github.com/yeoman/grunt-usemin#blocks
html: '<%= settings.dir.src %>/index.html'
},
watch: {
files: '<%= settings.dir.src %>/**',
options: {
livereload: '<%= connect.options.livereload %>'
},
scripts: {
files: '<%= settings.dir.src %>/js/*.js',
tasks: 'jshint',
options: {
spawn: false
}
}
}
});
// -------------------------------------------------------------------------
// | Main Tasks |
// -------------------------------------------------------------------------
// build task
grunt.registerTask('build', [
'clean:all',
'copy',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'filerev',
'usemin',
'htmlmin',
'clean:tmp'
]);
// default task
// (same as `build`, as `build` will be used more often)
grunt.registerTask('default', [
'build'
]);
// development task
grunt.registerTask('dev', [
'connect:livereload',
'watch'
]);
grunt.registerTask('test', [
'jshint',
'build'
]);
};