forked from minamarkham/sassy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
158 lines (133 loc) · 4.23 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
/*
Grunt installation:
-------------------
npm install -g grunt-cli
npm install -g grunt-init
npm init (creates a `package.json` file)
Simple Dependency Install:
--------------------------
npm install (from the same root directory as the `package.json` file
Tasks:
--------------------------
grunt (default is to watch both sass and coffeescript files)
grunt sass (compile once)
grunt watch (you can also explicitly call the watch task)
All commands are detailed by running the following:
--------------------------
grunt --help
*/
module.exports = function(grunt) {
// CONFIG ===================================/
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// configure sass --> grunt sass
sass: { // Task
dev: { // Target
options: { // Target options
style: 'expanded'
},
files: { // Dictionary of files
'css/styles.css': 'scss/styles.scss', // 'destination': 'source'
'css/ie.css': 'scss/ie.scss',
'css/themes/*.css':'scss/themes/*.scss'
}
},
prod: { // Target
options: { // Target options
style: 'compressed'
},
files: { // Dictionary of files
'css/styles.css': 'scss/styles.scss', // 'destination': 'source'
'css/ie.css': 'scss/ie.scss',
'css/themes/*.css':'scss/themes/*.scss'
}
}
},
// configure sass documentation --> grunt sassdoc
sassdoc: {
default: {
src: 'scss',
dest: 'docs',
options: {
package: 'package.json'
}
}
},
// configure concatenation --> grunt concat
concat: {
dist: {
src: [
'js/libs/*.js' // All JS in the libs folder
],
dest: 'js/plugins.js'
}
},
// configure minification --> grunt uglify
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
dist: {
files: {
'js/build/plugins.js' : 'js/plugins.js',
'js/build/global.js' : 'js/global.js'
}
}
},
// configure file watching --> grunt watch
watch: {
scripts: {
files: ['js/**/*.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: false,
},
},
css: {
files: ['scss/**/*.scss'],
tasks: ['sass:dev'],
options: {
spawn: false,
}
},
docs: {
files: ['scss/**/*.scss'],
tasks: ['sassdoc'],
options: {
spawn: false,
}
}
},
// configure image optimization --> grunt imagemin
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'img/',
src: ['**/*.{png,jpg,gif}'],
dest: 'img/build/'
}]
}
}
});
// DEPENDENT PLUGINS =========================/
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-sassdoc');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-watch');
// TASKS =====================================/
grunt.registerTask( 'default', [ 'watch'] ); // default 'grunt'
grunt.registerTask( 'build', [ 'imagemin','sass:prod' ] ); // optimize images, compress css
};
/*
Notes:
When registering a new Task we can also pass in any other registered Tasks.
e.g. grunt.registerTask('release', 'default requirejs'); // when running this task we also run the 'default' Task
We don't do this above as we would end up running `sass:dev` when we only want to run `sass:dist`
We could do it and `sass:dist` would run afterwards, but that means we're compiling sass twice which (although in our example quick) is extra compiling time.
To run specific sub tasks then use a colon, like so...
grunt sass:dev
grunt sass:dist
*/