-
Notifications
You must be signed in to change notification settings - Fork 21
/
makeBundle.js
41 lines (33 loc) · 1.15 KB
/
makeBundle.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
#!/usr/bin/env node
var derequire = require('derequire');
var browserify = require('browserify');
var shim = require('browserify-shim');
var fs = require('fs');
var UglifyJS = require('uglify-js');
var pack = require('./package.json');
var inputFile = './index.js';
var outputFile = './dist/immstruct.js';
var outputMinifiedFile = './dist/immstruct.min.js';
var header = generateHeader();
var b = browserify({
standalone: 'immstruct'
});
b.add(inputFile);
b.exclude('immutable');
b.transform(shim);
b.bundle(function(err, buf){
var code = buf.toString();
code = code.replace(/require\(('|")immutable('|")\)/ig, '(typeof window !== "undefined" ? window.Immutable : typeof global !== "undefined" ? global.Immutable : null)');
code = header + derequire(code);
fs.writeFileSync(outputFile, code);
var minfied = UglifyJS.minify(outputFile);
fs.writeFileSync(outputMinifiedFile, header + minfied.code);
});
function generateHeader() {
var header = '';
header = '/**\n';
header += '* immstruct v' + pack.version + '\n';
header += '* A part of the Omniscient.js project\n';
header += '***************************************/\n';
return header;
}