This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
forked from knpuniversity/symfonycon-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
181 lines (163 loc) · 7 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
module.exports = function (grunt) {
// globs where our JS files are found - used below in uglify and watch
var jsFilePaths = [
'js/*.js',
'js/app/*.js',
'js/app/modules/*.js'
];
// Project configuration
grunt.initConfig({
// you can read in JSON files, which are then set as objects. We use this below with banner
pkg: grunt.file.readJSON('package.json'),
// setup some variables that we'll use below
appDir: 'web/assets',
builtDir: 'web/assets-built',
requirejs: {
// creates a "main" requirejs sub-task (grunt requirejs:main)
// we *could* have other sub-tasks for using requirejs with other
// files or configuration
main: {
options: {
mainConfigFile: '<%= appDir %>/js/common.js',
appDir: '<%= appDir %>',
baseUrl: './js',
dir: '<%= builtDir %>',
// will be taken care of with compass
optimizeCss: "none",
// will be taken care of with an uglify task directly
optimize: "none",
/**
* The list of modules that should have their dependencies packed into them.
*
* For each module listed here, Require.js will read
* that modules dependencies and package them in the
* file. It will additionally add in any modules (and
* their dependencies) specified in the "include" and
* exclude any modules (and their dependencies) specified
* in "exclude".
*/
modules: [
// First set up the common build layer.
{
// module names are relative to baseUrl
name: 'common',
// List common dependencies here. Only need to list
// top level dependencies, "include" will find
// nested dependencies inside each of these
include: ['jquery', 'domReady', 'bootstrap']
},
// Now set up a build layer for each page, but exclude
// the common one. "exclude" will exclude nested
// the nested, built dependencies from "common". Any
// "exclude" that includes built modules should be
// listed before the build layer that wants to exclude it.
// "include" the appropriate "app/main*" module since by default
// it will not get added to the build since it is loaded by a nested
// require in the page*.js files.
{
// module names are relative to baseUrl/paths config
name: 'app/homepage',
exclude: ['common']
}
]
}
}
},
uglify: {
options: {
// a cute way to put a banner on each uglified file
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
/*
* I'm not sure if finding files recursively is possible. This is
* a bit ugly, but it accomplishes the task of finding all files
* in the built directory (that we want) and uglifying them.
*
* Additionally, I created a little self-executing function
* here so that I could re-use the jsFilePaths from above
*
* https://github.com/gruntjs/grunt-contrib-uglify/issues/23
*/
files: (function() {
var files = [];
jsFilePaths.forEach(function(val) {
files.push({
expand: true,
cwd: '<%= builtDir %>',
src: val,
dest: '<%= builtDir %>'
});
});
return files;
})()
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'<%= appDir %>/js/{,*/}*.js'
]
},
// use compass to compile everything in the "sass" directory into "css"
compass: {
// the "production" build subtask (grunt compass:dist)
dist: {
options: {
sassDir: '<%= builtDir %>/sass',
cssDir: '<%= builtDir %>/css',
environment: 'production',
outputStyle: 'compressed'
}
},
// the "development" build subtask (grunt compass:dev)
dev: {
options: {
sassDir: '<%= appDir %>/sass',
cssDir: '<%= appDir %>/css',
outputStyle: 'expanded'
}
}
},
// run "Grunt watch" and have it automatically update things when files change
watch: {
// watch all JS files and run jshint
scripts: {
// self executing function to reuse jsFilePaths, but prefix each with appDir
files: (function() {
var files = [];
jsFilePaths.forEach(function(val) {
files.push('<%= appDir %>/'+val);
});
return files;
})(),
tasks: ['jshint'],
options: {
spawn: false
}
},
// watch all .scss files and run compass
compass: {
files: '<%= appDir %>/sass/*.scss',
tasks: ['compass:dev'],
options: {
spawn: false
}
}
}
});
// Load tasks from our external plugins. These are what we're configuring above
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
// the "default" task (e.g. simply "Grunt") runs tasks for development
grunt.registerTask('default', ['jshint', 'compass:dev']);
// register a "production" task that sets everything up before deployment
grunt.registerTask('production', ['jshint', 'requirejs', 'uglify', 'compass:dist']);
};