-
Notifications
You must be signed in to change notification settings - Fork 217
/
Gruntfile.js
83 lines (76 loc) · 3.21 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
var Browserify = require('browserify');
var bresolve = require('browser-resolve');
patchResolve();
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
outputFolder: ".",
browserify: {
main: {
src: ['index.js'],
dest: '<%= outputFolder %>/<%= pkg.name %>.js',
options: {
browserifyOptions: { standalone: '<%= pkg.name %>' },
banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n',
alias: {
"jsonpath": "./index.js"
},
require: [
/**
* When running in Node, we require('./aesprim') and that module takes care of monkey-patching esprima
* using resolve, path finding, etc...
* Anyways, Browserify doesn't support "resolve", so we need to trick the module. We'll actually be
* returning a verbatim, non-modified "esprima" when the code runs require('./aesprim').
* That is ok because we will modify the "esprima" source code right after the bundle process, via
* the postBundleCB callback.
*/
["esprima", {expose: "./aesprim"}]
],
ignore: [
'file',
'system',
'source-map',
'estraverse',
'escodegen',
'underscore',
'reflect',
'JSONSelect',
'./lib/aesprim.js'
//'assert' //can't remove because of lib/index.js,
],
postBundleCB: function(err, src, next) {
/**
* This is ugly, but we need to make "esprima" understand '@' as a valid character.
* It's either this or bundle a copy of the library with those few bytes of changes.
*/
src = src.toString("utf8").replace(/(function isIdentifierStart\(ch\) {\s+return)/m, '$1 (ch == 0x40) || ');
next(err, new Buffer(src, "utf8"));
}
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n'
},
build: {
src: '<%= outputFolder %>/<%= pkg.name %>.js',
dest: '<%= outputFolder %>/<%= pkg.name %>.min.js'
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.registerTask('default', ['browserify', 'uglify']);
};
function patchResolve() {
var _createDeps = Browserify.prototype._createDeps;
Browserify.prototype._createDeps = function() {
var returnValue = _createDeps.apply(this, arguments);
this._bresolve = function(id, opts, cb) {
opts.browser = 'alias';
return bresolve(id, opts, cb);
};
return returnValue;
}
}