-
Notifications
You must be signed in to change notification settings - Fork 19
/
Gruntfile.js
116 lines (109 loc) · 3.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
'use strict';
const config = require('./app/config.json');
const TARGET = process.env.npm_lifecycle_event;
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
'cache-busting': {
libsJs: {
replace: ['./index.html'],
replacement: 'libs.js',
file: './build/libs.js',
cleanup: true
},
vendorJs: {
replace: ['./index.html'],
replacement: 'vendor.js',
file: './build/vendor.js',
cleanup: true
},
web_components_vendorJs: {
replace: ['./index.html'],
replacement: 'web_components_vendor.js',
file: './build/web_components_vendor.js',
cleanup: true
},
indexJs: {
replace: ['./index.html'],
replacement: 'index.js',
file: './build/index.js',
cleanup: true
},
css: {
replace: ['./index.html'],
replacement: 'styles.min.css',
file: './build/styles.min.css',
cleanup: true
}
},
strip_code: {
options: {
blocks: [
{
start_block: '/* staging-code */',
end_block: '/* end-staging-code */'
}
]
},
target: {
src: `${config.PATHS.app}/app.jsx`,
dest: `${config.PATHS.app}/app.jsx`
}
},
replace: {
js_images: {
options: {
patterns: [
{
match: new RegExp('src:"./images/', 'g'),
replacement: () => `src:"${config[TARGET].assetHost}/images/`
}
]
},
files: [
{
src: ['./build/index.js'],
dest: './'
}
]
},
fonts: {
options: {
patterns: [
{
match: new RegExp('../fonts/', 'g'),
replacement: () => `${config[TARGET].assetHost}/fonts/`
}
]
},
files: [
{
src: ['./build/styles.min.css'],
dest: './'
}
]
},
css_images: {
options: {
patterns: [
{
match: new RegExp('../images/', 'g'),
replacement: () => `${config[TARGET].assetHost}/images/`
}
]
},
files: [
{
src: ['./build/styles.min.css'],
dest: './'
}
]
}
}
});
grunt.loadNpmTasks('grunt-cache-busting');
grunt.loadNpmTasks('grunt-strip-code');
grunt.loadNpmTasks('grunt-replace');
grunt.registerTask('remove-code', ['strip_code']);
grunt.registerTask('default', ['replace', 'cache-busting']);
};