-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgruntfile.js
53 lines (51 loc) · 1.64 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
const path = require('path');
//set up global constants for all grunt tasks
const env = process.env.NODE_ENV || 'development';
const src = path.resolve(__dirname, './src/front-end');
const tmp = path.resolve(__dirname, './tmp/grunt');
const build = path.resolve(__dirname, './build/front-end');
global.gruntConfig = {
dir: {
src,
tmp,
build
},
src: {
static: `${src}/static`,
sass: `${src}/sass`,
ts: `${src}/typescript`,
tsShared: 'src/shared'
},
tmp: {
js: `${tmp}/js`,
frontEnd: `${tmp}/js/front-end/typescript`,
shared: `${tmp}/js/shared`
},
out: {
css: `${build}/app.css`,
js: `${build}/app.js`,
html: `${build}/`
}
};
//dependencies
const loadTasks = require('load-grunt-tasks');
const requireDir = require('require-dir');
const _ = require('lodash');
const gruntConfigs = requireDir('./grunt-configs');
module.exports = function (grunt) {
//load grunt tasks from package.json
loadTasks(grunt);
//initialize the grunt configs for various loaded tasks
grunt.config.init(
_.mapValues(gruntConfigs, (v) => {
return _.isFunction(v) ? v(grunt) : v;
})
);
//create task lists for dev and prod envs
grunt.registerTask('common', ['clean', 'copy', 'sass', 'postcss:prefix', 'shell:typescript', 'browserify']);
grunt.registerTask('development-build', ['common', 'compress']);
grunt.registerTask('development-watch', ['development-build', 'watch']);
grunt.registerTask('production-build', ['common', 'postcss:min', 'terser:production', 'htmlmin:production', 'compress']);
grunt.registerTask('build', [`${env}-build`]);
grunt.registerTask('default', ['development-watch']);
};