-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
215 lines (193 loc) · 4.69 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
209
210
211
212
213
214
215
module.exports = function (grunt) {
// load plugins
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-filerev');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-version');
grunt.loadNpmTasks('grunt-wiredep');
// configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
///// build project
// clean folders
clean: {
tmp: ['.tmp'],
dist: ['dist/*']
},
// copy files from src to dist folder
copy: {
dist: {
files: [
{expand: true, cwd: 'src/', src: 'index.html', dest: 'dist/'},
{expand: true, cwd: 'src/', src: 'fonts/**/*', dest: 'dist/'},
// {expand: true, cwd: 'src/', src: 'bower_components/font-awesome/fonts/*', dest: 'dist/fonts/', flatten: true},
{expand: true, src: 'node_modules/@fortawesome/fontawesome-free/webfonts/*', dest: 'dist/fonts/', flatten: true},
{expand: true, cwd: 'src/', src: 'img/**/*.{png,jpg,svg,gif}', dest: 'dist/'}
]
}
},
// copy html partials without comments
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true
},
files: [
{expand: true, cwd: 'src/', src: 'app/**/*.html', dest: 'dist/'},
{expand: true, cwd: 'src/', src: 'components/**/*.html', dest: 'dist/'},
{expand: true, cwd: 'src/', src: 'partials/**/*.html', dest: 'dist/'}
]
}
},
// identify build blocks and prepare minification
useminPrepare: {
options: {
root: './',
dest: 'dist',
flow: {
html: {
steps: {
js: ['concat', 'uglify'],
css: ['cssmin']
},
post: {}
}
}
},
html: 'dist/index.html'
},
// cssmin: {
// options: {
// root: 'src'
// }
// },
// static asset revisioning through file content hash
filerev: {
options: {
algorithm: 'md5',
length: 8
},
dist: {
src: [
'dist/app/**/*.html',
'dist/components/**/*.html',
'dist/partials/**/*.html',
'dist/script/**/*.js',
'dist/style/**/*.css',
'dist/img/**/*.{png,jpg,svg,gif}'
]
}
},
// replace references
usemin: {
html: ['dist/**/*.html'],
css: 'dist/style/*.css',
js: 'dist/script/*.js',
options: {
assetsDirs: ['dist'],
patterns: {
html: [
[/src="([^:'"]+)"/img, 'src replacement in html files'],
[/ng-include="'([^:'"]+)'"/img, 'ng-include replacement in html files'],
[/template-url="([^:'"]+)"/img, 'template-url replacement in html files']
],
js: [
[/(?:templateUrl|contentTemplate):[\s]*['"]([^:'"]+\.html)['"]/img, 'Partials replacement in js files'],
[/\.load\(['"]([^:'"]+)['"][,)]/img, 'TextureLoader image url']
],
css: [
[/url\((?:\.\.\/)*((?!\.\.\/)[^:'"?#()]+)(?:[?#][^:'"?()]+)?\)/img, 'Url replacement in css files']
]
}
}
},
// correct css url references
'string-replace': {
'src-path': {
files: {
'dist/': 'dist/index.html'
},
options: {
replacements: [{
pattern: /<script([^>]+)src="(?!node_modules)([^"]+)"/g,
replacement: '<script$1src="src/$2"'
}, {
pattern: /<link([^>]+)href="(?!node_modules)([^"]+)"/g,
replacement: '<link$1href="src/$2"'
}]
}
},
'css-fix': {
files: {
'dist/': 'dist/style/*.css'
},
options: {
replacements: [{
pattern: /url\((?:\.\.\/)*((?!\.\.\/)[^:'"()]+)\)/ig,
replacement: 'url(../$1)'
}, {
pattern: /\/webfonts\//g,
replacement: '/fonts/'
}]
}
}
},
///// misc
// convert CommonJS file to browser compatible js file
browserify: {
exports: {
src: 'src/lib/exports.js',
dest: 'src/lib/browserify.js'
}
},
// update versions
version: {
js: {
options: {
prefix: '@version\\s'
},
src: ['src/app/app.js']
},
html: {
options: {
prefix: '>\\s*v'
},
src: ['src/app/header/header.tpl.html']
},
packages: {
src: ['package.json', 'bower.json']
}
},
// wire bower dependencies to index.html
wiredep: {
target: {
src: ['src/index.html']
}
}
});
// tasks
grunt.registerTask('default', ['wiredep']);
grunt.registerTask('build', [
'clean:dist',
'copy:dist',
'string-replace:src-path',
'htmlmin:dist',
'useminPrepare',
'concat:generated',
'cssmin:generated',
'uglify:generated',
'filerev',
'usemin',
'string-replace:css-fix',
'clean:tmp'
]);
};