-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
85 lines (80 loc) · 2.51 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
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
env: {
build: {
src: ".env"
}
},
json: {
main: {
options: {
namespace: 'CONFIG',
includePath: false,
pretty: true,
processContent: function (content) {
content.base_url = process.env.BASE_URL;
return content;
}
},
src: ['js/config/**.json'],
dest: 'js/config.js'
}
},
uglify: {
build: {
sourceMap: true,
files: {
'dist/js/main.min.js': ['js/config.js', 'js/main.js']
}
}
},
useminPrepare: {
html: 'index.html',
options: {
dest: 'dist'
}
},
usemin: {
html: 'dist/index.html'
},
copy: {
main: {
files: [
// includes files within path
{
expand: true,
src: ['images/**'],
dest: 'dist/'
},
// includes files within path
{
expand: true,
src: ['css/**'],
dest: 'dist/'
},
// includes files within path and its sub-directories
{
expand: true,
src: ['index.html'],
dest: 'dist/'
}
],
},
},
});
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-json');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('check-env', 'Check env vars', function () {
grunt.log.writeln('Checking required env vars...');
if (process.env.BASE_URL === undefined) {
grunt.fail.fatal("Error: BASE_URL environtment variable not set.");
}
});
grunt.registerTask('build:dev', ['env:build', 'check-env', 'json']);
grunt.registerTask('build', ['env:build', 'check-env', 'json', 'uglify', 'copy', 'usemin']);
};