This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gruntfile.js
217 lines (197 loc) · 6.09 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
216
217
const timeGrunt = require('time-grunt')
const gruntWriteJson = require('./modules/grunt-write-json')
const jitGrunt = require('jit-grunt')
const gettext = require('./modules/gettext')
module.exports = function (grunt) {
'use strict'
// Track execution time
timeGrunt(grunt)
gruntWriteJson(grunt)
// Load grunt tasks automatically
jitGrunt(grunt, {
nunjucks: 'grunt-nunjucks-2-html',
sprite: 'grunt-spritesmith',
'webpack-dev-server': 'grunt-webpack'
})
// Define the configuration for all the tasks
grunt.initConfig({
// Specify environment variables
env: {
sitename: process.env.SITENAME,
production: (process.env.PRODUCTION === 'true') || grunt.option('production'),
staging: (process.env.STAGING === 'true') || grunt.option('staging'),
build: (process.env.BUILD === 'true') || grunt.cli.tasks.includes('build') || grunt.option('build'),
buildSHA1: process.env.CIRCLE_SHA1,
buildNumber: process.env.CIRCLE_BUILD_NUM,
hotModuleRloading: grunt.option('hmr'),
tinypng: {
api: {
key: process.env.TINYPNG_API_KEY
}
},
github: {
api: {
key: process.env.GITHUB_API_KEY
}
}
},
// Specify your source and build directory structure
path: {
tasks: {
root: 'tasks'
},
source: {
root: 'source',
data: '<%= path.source.root %>/data',
fonts: '<%= path.source.root %>/fonts',
icons: '<%= path.source.root %>/icons',
images: '<%= path.source.root %>/images',
locales: '<%= path.source.root %>/locales',
scripts: '<%= path.source.root %>/scripts',
sprites: '<%= path.source.root %>/sprites',
static: '<%= path.source.root %>/static',
styles: '<%= path.source.root %>/styles',
templates: '<%= path.source.root %>/templates'
},
temp: {
root: 'temp',
data: '<%= path.temp.root %>/data',
styles: '<%= path.temp.root %>/styles'
},
build: {
root: 'build',
assets: '<%= path.build.root %>/assets',
fonts: '<%= path.build.assets %>/fonts',
images: '<%= path.build.assets %>/images',
scripts: '<%= path.build.assets %>/scripts',
sprites: '<%= path.build.assets %>/sprites',
static: '<%= path.build.root %>',
styles: '<%= path.build.assets %>/styles',
templates: '<%= path.build.root %>'
}
},
// Specify files
file: {
source: {
data: {
scripts: '<%= path.source.data %>/scripts.js'
},
scripts: {
main: '<%= path.source.scripts %>/main.js',
serviceWorker: '<%= path.source.scripts %>/serviceWorker/sw.js'
}
},
temp: {
data: {
matter: '<%= path.temp.data %>/matter.json',
images: '<%= path.temp.data %>/images.json',
scripts: '<%= path.temp.data %>/scripts.js'
}
},
build: {
// Note that Webpack paths configuration is tricky at times.
// For instance, `scriptMinifiedExt` will affect other paths, like `runtime` and
// `externals` and there is no straight way to change that Webpack behaviour.
// The way Kotsu `compiled` and `minified` paths concatenated exactly represents that relation.
// Also, `runtime` name can't be changed without messing directly with related Webpack plugin.
scriptMinifiedExt: 'min',
script: {
name: 'main',
compiled: '<%= path.build.scripts %>/<%= file.build.script.name %>.js',
minified: '<%= path.build.scripts %>/<%= file.build.script.name %>.<%= file.build.scriptMinifiedExt %>.js'
},
scriptRuntime: {
name: 'runtime',
compiled: '<%= path.build.scripts %>/<%= file.build.scriptRuntime.name %>.js',
minified: '<%= path.build.scripts %>/<%= file.build.scriptRuntime.name %>.<%= file.build.scriptMinifiedExt %>.js'
},
scriptExternals: {
name: 'externals',
compiled: '<%= path.build.scripts %>/<%= file.build.scriptExternals.name %>.js',
minified: '<%= path.build.scripts %>/<%= file.build.scriptExternals.name %>.<%= file.build.scriptMinifiedExt %>.js'
},
serviceWorker: {
compiled: '<%= path.build.root %>/sw.js',
minified: '<%= path.build.root %>/sw.<%= file.build.scriptMinifiedExt %>.js'
},
sprite: {
compiled: '<%= path.build.sprites %>/sprite.png'
}
}
},
locales: {
'en-US': {
locale: 'en-US',
url: '/',
rtl: false,
defaultForLanguage: true,
numberFormat: '0,0.[00]',
currencyFormat: '$0,0.00'
},
'ru-RU': {
locale: 'ru-RU',
url: '/ru',
rtl: false,
defaultForLanguage: true,
numberFormat: '0,0.[00]',
currencyFormat: '0,0.00 $'
}
},
baseLocale: 'en-US'
})
grunt.config.merge({
gettext: gettext(grunt.config('path.source.locales')),
data: require(`./${grunt.config('path.source.data')}`)(grunt)
})
grunt.loadTasks(grunt.config('path.tasks.root'))
// Build for development and serve
grunt.registerTask('default', [
'clean:build',
'clean:temp',
'writeJSON',
'copy',
'responsive_images:thumbnails',
'image_size',
'grayMatter',
'nunjucks',
'sprite',
'webfont',
'sass',
'postcss:autoprefix',
'webpack-dev-server:watch',
'webpack:watchServiceWorker',
'watch'
])
// Build for production
grunt.registerTask('build', [
'clean:build',
'clean:temp',
'writeJSON',
'copy',
'responsive_images:thumbnails',
'image_size',
'grayMatter',
'nunjucks',
'sprite',
'webfont',
'sass',
'postcss:autoprefix',
'webpack:build',
'uncss',
'csso',
'htmlmin',
'tinypng',
'clean:styles',
'cacheBust',
'sitemap_xml',
'webpack:buildServiceWorker',
'size_report'
])
// Serve built version
grunt.registerTask('serve', [
'webpack-dev-server:watch',
'webpack:watchServiceWorker',
'watch'
])
return grunt
}