-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGruntfile.js
170 lines (155 loc) · 4.68 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
'use strict';
module.exports = function(grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
var config = {
srcDir: 'src',
distDir: 'dist',
stageDir: 'stage',
testDir: 'test',
exampleDir: 'example',
distName:'manifestor.js',
// add any additional js/less/html files to build here:
lessToBuild: ['example/styles/main.less'],
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: config,
headerInfo: '/*\n' +
' <%= pkg.name %>\n' +
' version: <%= pkg.version %>\n' +
' <%= pkg.homepage %>\n' +
' Browserified module compilation\n' +
'*/\n',
// clean out old files from build folders
clean: {
dist: {
files: [{
dot: true,
src: ['<%= config.distDir %>/*', '!<%= config.distDir %>/.git*']
}]
}
},
// bundle JS with browserify
browserify: {
stage: {
options: {
browserifyOptions: {
standalone: 'manifestor'
}
},
src: ['src/main.js'],
dest: '<%= config.stageDir %>/manifestor.js'
},
dist: {
options: {
browserifyOptions: {
standalone: 'manifestor'
}
},
src: ['src/main.js'],
dest: '<%= config.distDir %>/manifestor.js'
}
},
// compile LESS to CSS
less: {
example: {
options: {
cleancss: true
},
files: {
'example/styles/main.css': [config.lessToBuild]
}
}
},
// run uglify on JS to minify it
uglify: {
dist: {
files: {
'dist/manifestor.min.js': 'dist/manifestor.js'
}
}
},
// web server for serving files from example
connect: {
example : {
options: {
port: '4000'
}
}
},
// watch files for changes and run appropriate tasks to rebuild build/Example
watch: {
js: {
files: '<%= config.srcDir %>/**/*.*',
tasks: ['smash', 'browserify:stage']
},
grunt: {
files: 'Gruntfile.js',
tasks: ['less:example', 'browserify:stage']
},
less: {
files: '<%= config.exampleDir %>/styles/**/*.*',
tasks: ['less:example']
},
browserify: {
files: '<%= config.src %>/scripts/**/*.*',
tasks: ['browserify:stage']
}
},
smash: {
bundle: {
src: 'src/lib/d3-slim.js',
dest: 'src/lib/d3-slim-dist.js'
}
},
header: {
stage: {
options: {
text: '<%= headerInfo %>'
},
files: {
'stage/manifestor.js': 'stage/manifestor.js'
}
},
dist: {
options: {
text: '<%= headerInfo %>'
},
files: {
'<%= config.distDir %>/manifestor.js': '<%= config.distDir %>/manifestor.js',
'<%= config.distDir %>/manifestor.min.js': '<%= config.distDir %>/manifestor.min.js'
}
}
},
bump: {
options: {
files: ['package.json', '<%= config.distDir %>/*.js'],
commitFiles: ['package.json', '<%= config.distDir %>/*.js'],
}
}
});
// Example tasks
grunt.registerTask('buildExample', [
'smash', // build custom D3 package
'browserify:stage', // bundle JS with browserify
'header:stage',
'less:example', // compile LESS to CSS
]);
grunt.registerTask('serveExample', [
'buildExample', // steps to run before refresh
'connect:example', // web server for serving files from build/Example
'watch' // watch src files for changes and rebuild when necessary
]);
// Distribution tasks
grunt.registerTask('buildDist', [
'smash', // build custom D3 package
'browserify:dist', // bundle JS with browserify
'uglify:dist', // minify JS files
'header:dist'
]);
// Task aliases
grunt.registerTask('build', ['buildDist']);
grunt.registerTask('serve', ['serveExample']);
grunt.registerTask('debug', ['serveExample']);
};