-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgruntfile.js
164 lines (148 loc) · 3.63 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
module.exports = function(grunt) {
grunt.initConfig({
// Variables
dirs: {
output: 'public'
},
// Clear the build directory
clean: ['<%= dirs.output %>'],
// Optimizes the images
image: {
dynamic: {
files: [{
expand: true,
cwd: 'src/img/',
src: ['**/*.{png,jpg,gif,svg}'],
dest: '<%= dirs.output %>/img'
}]
}
},
// Compiles SASS files with sourcemaps
sass: {
dist: {
options: {
sourcemap: true,
style: 'expanded'
},
files: {
'<%= dirs.output %>/style.css': 'src/css/style.scss'
}
}
},
// Adds prefixes, rem fallbacks and compact the css
postcss: {
options: {
map: true,
processors: [
require('autoprefixer')({
browsers: ['last 3 versions', 'ie 8', 'android 4']
}), // add vendor prefixes
require('pixrem')(), // add fallbacks for rem units
require('cssnano')() // minify the result
]
},
dist: {
src: '<%= dirs.output %>/**/*.css'
}
},
// Minify your javascripts
uglify: {
options: {
mangle: false
},
my_target: {
files: [{
expand: true,
cwd: 'src/js',
src: '**/*.js',
dest: 'js'
}]
}
},
// Creates a dedicated ie.css with all the MQ's
match_media: {
ie: {
files: {
'<%= dirs.output %>/ie.css': ['<%= dirs.output %>/style.css']
}
}
},
// Compress CSS
csso: {
dynamic_mappings: {
expand: true,
cwd: '<%= dirs.output %>/css/',
src: ['*.css', '!*.min.css'],
dest: 'build/css/',
ext: '.css'
}
},
// Launchs a server with livereload included
connect: {
client: {
options: {
port: 8050,
base: 'build/',
hostname: '*',
livereload: true
}
}
},
// Copies fonts and images when developing for faster building
copy: {
img: {
expand: true,
cwd: 'src/img/',
src: '**/**.{png,jpg,gif}',
dest: '<%= dirs.output %>/img',
flatten: false,
filter: 'isFile'
},
fonts: {
expand: true,
cwd: 'src/fonts/',
src: '**/**.{eot,ttf,woff,woff2}',
dest: '<%= dirs.output %>/fonts',
flatten: false,
filter: 'isFile'
}
},
// Configures the watch task
watch: {
options: {
livereload: true,
},
css: {
files: ['src/css/**/**.scss'],
tasks: ['sass', 'postcss']
},
uglify: {
files: ['src/js/**/**.js'],
tasks: ['uglify']
},
imagemin: {
files: ['src/img/**/*.{png,jpg,gif}'],
tasks: ['copy:img']
}
}
});
// Load the plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-image');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-match-media');
grunt.loadNpmTasks('grunt-csso');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-clean');
// Register the tasks
grunt.registerTask('default', ['watch']);
grunt.registerTask('build', ['clean',
'sass',
'image',
'postcss',
'match_media',
'csso',
'uglify']);
}