-
Notifications
You must be signed in to change notification settings - Fork 2
/
gruntfile.js
executable file
·180 lines (171 loc) · 5.02 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
// NOTE if you get infinite loop on grunt watch, make sure all packages are installed, especially npm install grunt-postcss pixrem autoprefixer cssnano for somereason this omits packages form the package.json file.
require('dotenv').config()
module.exports = function (grunt) {
// SITE STYLE
const siteTheme = process.env.SITE_THEME
const siteRoot = `site/themes/${siteTheme}`
const siteScssRoot = `site/themes/${siteTheme}/scss/`
const siteGlobbedScssDestination = `${siteRoot}/scss/style.scss`
const sitePublicStyleDestination = `${siteRoot}/public/css/style.css`
// SITE JS
const siteJsBundledJsFile = `${siteRoot}/public/js/bundle.js`
const siteJsFinalOutput = `${siteRoot}/public/js/main.min.js`
// CMS STYLE
const cmsRoot = 'cms'
const cmsGlobbedScssDestination = `${cmsRoot}/scss/style.scss`
const cmsScssRoot = `${cmsRoot}/scss/`
const cmsPublicStyleDestination = `${cmsRoot}/public/css/style.css`
// CMS JS
const cmsJsBundledJsFile = `${cmsRoot}/public/js/bundle.js`
const cmsJsFinalOutput = `${cmsRoot}/public/js/main.min.js`
require('load-grunt-tasks')(grunt, {
scope: 'devDependencies'
})
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// main jsmin task
uglify: {
cms: {
src: [
`${cmsRoot}/**/_*.js`
],
dest: cmsJsBundledJsFile
},
site: {
src: [
`${siteRoot}/**/_*.js`
],
dest: siteJsBundledJsFile
}
},
babel: {
options: {
sourceMap: true,
minified: true,
presets: [
['@babel/preset-env']
]
},
dist: {
files: {
[cmsJsFinalOutput]: cmsJsBundledJsFile,
[siteJsFinalOutput]: siteJsBundledJsFile
}
}
},
browserify: {
cms: {
src: [cmsJsBundledJsFile],
dest: cmsJsBundledJsFile,
options: {
external: ['jquery']
}
},
site: {
src: [siteJsBundledJsFile],
dest: siteJsBundledJsFile,
options: {
external: ['jquery']
}
}
},
// concats all the sass partials for compilation later, need them in this order, avoid wildcards
sass_globbing: {
site: {
files: {
[siteGlobbedScssDestination]: [
`${siteScssRoot}_variables.scss`,
`${siteScssRoot}_normalize.scss`,
`${siteScssRoot}_globals.scss`,
`${siteScssRoot}_basic-style.scss`,
`${siteScssRoot}_utilities.scss`,
`${siteRoot}/**/_*.scss`,
// add media last to ensure it always has precidence
`${siteScssRoot}_media.scss`
]
},
options: {
useSingleQuotes: false,
signature: '// Style by Colin Mackenzie - Viral Edge'
}
},
cms: {
files: {
[cmsGlobbedScssDestination]: [
`${cmsScssRoot}_variables.scss`,
`${cmsScssRoot}_globals.scss`,
`${cmsScssRoot}_basic-style.scss`,
`${cmsScssRoot}_bootstrap-overrides.scss`,
`${cmsRoot}/**/_*.scss`
]
},
options: {
useSingleQuotes: false,
signature: '// Style by Colin Mackenzie - Viral Edge'
}
}
},
// convert the scss into css
sass: {
site: {
options: {
style: 'expanded' // minified in postcss
},
files: {
[sitePublicStyleDestination]: [siteGlobbedScssDestination]
}
},
cms: {
options: {
style: 'expanded'
},
files: {
[cmsPublicStyleDestination]: [cmsGlobbedScssDestination]
}
}
},
// take our processed scss >> css and lint and augment the css
postcss: {
options: {
map: {
inline: false // save all sourcemaps as separate files...
},
processors: [
require('autoprefixer')(),
require('cssnano')()
]
},
dist: {
src: [sitePublicStyleDestination, cmsPublicStyleDestination]
}
},
watch: {
site_css: {
files: [`${siteRoot}/**/_*.scss`],
tasks: ['site-style-build']
},
cms_css: {
files: [`${cmsRoot}/**/_*.scss`],
tasks: ['cms-style-build']
},
cms_js: {
files: [`${cmsRoot}/**/_*.js`],
tasks: ['cms-js-build']
},
site_js: {
files: [`${siteRoot}/**/_*.js`],
tasks: ['site-js-build']
}
}
})
// Default task(s).
grunt.registerTask('cms-js-build', ['uglify:cms', 'browserify:cms', 'babel'])
grunt.registerTask('site-js-build', ['uglify:site', 'browserify:site', 'babel'])
grunt.registerTask('site-style-build', ['sass_globbing:site', 'sass:site', 'postcss'])
grunt.registerTask('cms-style-build', ['sass_globbing:cms', 'sass:cms'])
// utility func to dump grunt config. Useful if you are having any issues.
grunt.registerTask('printConfig', function () {
grunt.log.writeln(JSON.stringify(grunt.config(), null, 2))
})
}