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