-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.js
127 lines (113 loc) · 2.87 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
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: [
'**/*.js',
'Gruntfile.js',
'!node_modules/**/*',
'!browser/dist/**/*',
'!browser/example/assets/*.js',
'!browser/test/browserified_tests.js'
],
options: {
jshintrc: '.jshintrc'
}
},
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['test/**/*.js']
}
},
// remove all previous browserified builds
clean: {
dist: ['./browser/dist/**/*.js'],
tests: ['./browser/test/browserified_tests.js']
},
// browserify the module
browserify: {
// This browserify build be used by users of the module. It contains a
// UMD (universal module definition) and can be used via an AMD module
// loader like RequireJS or by simply placing a script tag in the page,
// which registers the module as a global var.
standalone: {
src: [ '<%= pkg.name %>.js' ],
dest: './browser/dist/<%= pkg.name %>.js',
options: {
browserifyOptions: {
standalone: '<%= pkg.name %>'
}
}
},
// This browserify build can be required by other browserify modules that
// have been created with an --external parameter.
external: {
src: [ '<%= pkg.name %>.js' ],
dest: './browser/dist/<%= pkg.name %>.external.js',
options: {
alias: [ './halfred.js:halfred' ]
}
},
// Browserified tests.
tests: {
src: [ 'test/browser_suite.js' ],
dest: './browser/test/browserified_tests.js',
options: {
external: [ './halfred.js:halfred' ],
browserifyOptions: {
// Embed source map for tests
debug: true,
}
}
}
},
// Uglify browser libs
uglify: {
dist: {
files: {
'browser/dist/<%= pkg.name %>.min.js':
['<%= browserify.standalone.dest %>'],
'browser/dist/<%= pkg.name %>.external.min.js':
['<%= browserify.external.dest %>']
}
}
},
// run the mocha tests in PhantomJS
mocha: {
test: {
src: [ 'browser/test/index.html' ],
options: {
timeout: 20000,
reporter: 'spec',
}
}
},
watch: {
files: ['<%= jshint.files %>', '**/*.json'],
tasks: ['default']
},
});
// load all grunt-tasks
require('load-grunt-tasks')(grunt);
grunt.registerTask('test', [
'jshint',
'mochaTest'
]);
grunt.registerTask('build', [
'clean',
'browserify',
'uglify'
]);
grunt.registerTask('test-browser', [
'mocha'
]);
grunt.registerTask('default', [
'test',
'build',
'test-browser'
]);
};