-
Notifications
You must be signed in to change notification settings - Fork 107
/
Gruntfile.js
179 lines (158 loc) · 5.53 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
/*!
* Grunt Configurations
*/
module.exports = function (grunt) {
'use strict';
var path = require('path');
var webpack = require('webpack');
var params = {
libName: 'geolocator', // lib variable
libFileName: 'geolocator', // file name
srcPath: path.resolve(__dirname, 'src'),
outPath: path.resolve(__dirname, 'dist'),
entryPath: path.resolve(__dirname, 'src/index.js'),
pagePath: path.resolve(__dirname, 'example/index.html'),
publicPath: 'dist/',
host: 'localhost',
port: 9991
};
params.baseURL = 'http://' + params.host + ':' + params.port + '/';
var webpackConfig = require('./webpack.config.js')(params);
// ----------------------------
// GRUNT CONFIG
// ----------------------------
grunt.initConfig({
// 'pkg': grunt.file.readJSON('package.json'),
// ----------------------------
// CONFIGURE TASKS
// ----------------------------
'docma': {
traceFatal: true,
options: {
config: './docma.config.json'
}
},
'copy': {
options: {
mode: false,
encoding: 'utf-8'
},
'example': {
files: [
{
expand: true,
nonull: true,
flatten: false,
// change working directory to copy the contents only,
// without the root folder "example"
cwd: 'example',
src: [
// copy the example folder contents to
// onury.github.io/geolocator-example directory,
// excluding iframed.html which is used by Docma config.
'**',
'!iframed.html'
],
dest: '../../onury.github.io/geolocator-example/'
}
]
},
'dist': {
files: [
{
expand: true,
src: [
'dist/geolocator.min.js'
],
dest: '../../onury.github.io/',
// rename geolocator.min.js to geolocator.js bec.
// example/index.html has reference to geolocator.js not
// geolocator.min.js - otherwise, webpack-server will
// not hot-update.
rename: function (dest) { // (dest, src)
return dest + 'dist/geolocator.js';
}
}
]
}
},
'webpack': {
options: webpackConfig.main,
watch: {
watch: true,
keepalive: true
},
full: {},
min: {
output: {
filename: params.libFileName + '.min.js'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
minimize: true,
sourceMap: true,
warnings: true
})
]
}
},
// this is for browser (manual) tests
'webpack-dev-server': webpackConfig.server,
// this is for jasmine tests
'connect': {
server: {
options: {
port: 8181
}
}
},
'jasmine': {
dist: {
src: 'dist/' + params.libFileName + '.js',
options: {
specs: 'test/*.spec.js',
helpers: 'test/*.helper.js',
host: 'http://localhost:8181/'
}
}
},
'watch': {
test: {
options: {
// Setting `spawn:false` is very problematic. See
// grunt-contrib- watch issues. (Default is `spawn:true`)
// spawn: false
},
files: [
'src/**/*',
'test/*.spec.js'
],
tasks: ['jasmine']
}
}
});
// ----------------------------
// LOAD GRUNT PLUGINS
// ----------------------------
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// ----------------------------
// REGISTER TASKS
// ----------------------------
grunt.registerTask('doc', ['docma', 'copy:example', 'copy:dist']);
grunt.registerTask('min', ['webpack:min']);
grunt.registerTask('build', ['webpack:full', 'webpack:min']);
grunt.registerTask('build-all', ['build', 'doc']);
grunt.registerTask('test', ['build', 'connect', 'watch:test']);
grunt.registerTask('watch-compile', ['watch:compile']);
// Open either one:
// http://localhost:8181/webpack-dev-server
// http://localhost:8181/example
// http://localhost:8181/webpack-dev-server/example
grunt.registerTask('serve', ['webpack-dev-server:start']);
grunt.registerTask('default', ['serve']);
// Development:
// run grunt build
// run 2 tasks in separate terminals:
// grunt serve (and open http://localhost:9991/example)
// grunt watch (for auto-compiling templates and auto-running jasmine tests)
};