source: frontend/node_modules/jsonpath/Gruntfile.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.2 KB
Line 
1var Browserify = require('browserify');
2var bresolve = require('browser-resolve');
3patchResolve();
4
5module.exports = function (grunt) {
6 grunt.initConfig({
7 pkg: grunt.file.readJSON('package.json'),
8 outputFolder: ".",
9
10 browserify: {
11 main: {
12 src: ['index.js'],
13 dest: '<%= outputFolder %>/<%= pkg.name %>.js',
14 options: {
15 browserifyOptions: { standalone: '<%= pkg.name %>' },
16 banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n',
17 alias: {
18 "jsonpath": "./index.js"
19 },
20 require: [
21 /**
22 * When running in Node, we require('./aesprim') and that module takes care of monkey-patching esprima
23 * using resolve, path finding, etc...
24 * Anyways, Browserify doesn't support "resolve", so we need to trick the module. We'll actually be
25 * returning a verbatim, non-modified "esprima" when the code runs require('./aesprim').
26 * That is ok because we will modify the "esprima" source code right after the bundle process, via
27 * the postBundleCB callback.
28 */
29 ["esprima", {expose: "./aesprim"}]
30 ],
31 ignore: [
32 'file',
33 'system',
34 'source-map',
35 'estraverse',
36 'escodegen',
37 'underscore',
38 'reflect',
39 'JSONSelect',
40 './lib/aesprim.js'
41 //'assert' //can't remove because of lib/index.js,
42 ],
43 postBundleCB: function(err, src, next) {
44 /**
45 * This is ugly, but we need to make "esprima" understand '@' as a valid character.
46 * It's either this or bundle a copy of the library with those few bytes of changes.
47 */
48 src = src.toString("utf8").replace(/(function isIdentifierStart\(ch\) {\s+return)/m, '$1 (ch == 0x40) || ');
49 next(err, new Buffer(src, "utf8"));
50 }
51 }
52 }
53 },
54
55 uglify: {
56 options: {
57 banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n'
58 },
59 build: {
60 src: '<%= outputFolder %>/<%= pkg.name %>.js',
61 dest: '<%= outputFolder %>/<%= pkg.name %>.min.js'
62 }
63 }
64
65 });
66
67 grunt.loadNpmTasks('grunt-browserify');
68 grunt.loadNpmTasks('grunt-contrib-uglify')
69 grunt.registerTask('default', ['browserify', 'uglify']);
70
71};
72
73function patchResolve() {
74 var _createDeps = Browserify.prototype._createDeps;
75 Browserify.prototype._createDeps = function() {
76 var returnValue = _createDeps.apply(this, arguments);
77 this._bresolve = function(id, opts, cb) {
78 opts.browser = 'alias';
79 return bresolve(id, opts, cb);
80 };
81 return returnValue;
82 }
83}
Note: See TracBrowser for help on using the repository browser.