forked from valor-software/ng2-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
umd-bundler.js
89 lines (77 loc) · 2.17 KB
/
umd-bundler.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
#!/usr/bin/env node
'use strict';
/*eslint no-console: 0, no-sync: 0*/
// UMD bundler
// simple and yet reusable system.js bundler
// bundles, minifies and gzips
const fs = require('fs');
const del = require('del');
const path = require('path');
const zlib = require('zlib');
const async = require('async');
const Builder = require('systemjs-builder');
const pkg = require('./package.json');
const name = pkg.name;
const targetFolder = path.resolve('./bundles');
async.waterfall([
cleanBundlesFolder,
getSystemJsBundleConfig,
buildSystemJs({minify: false, sourceMaps: true, mangle: false, noEmitHelpers: false, declaration: true}),
getSystemJsBundleConfig,
buildSystemJs({minify: true, sourceMaps: true, mangle: false, noEmitHelpers: false, declaration: true})
], err => {
if (err) {
throw err;
}
});
function getSystemJsBundleConfig(cb) {
const config = {
baseURL: '.',
transpiler: 'typescript',
typescriptOptions: {
module: 'cjs'
},
map: {
typescript: './node_modules/typescript/lib/typescript',
'@angular': './node_modules/@angular',
rxjs: './node_modules/rxjs/bundles',
lodash: './node_modules/lodash'
},
paths: {
'*': '*.js',
},
meta: {
'./node_modules/@angular/*': {build: false},
'./node_modules/rxjs/*': {build: false},
lodash: {build: false, main: 'lodash.js'}
}
};
return cb(null, config);
}
function cleanBundlesFolder(cb) {
return del(targetFolder)
.then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
cb();
});
}
function buildSystemJs(options) {
return (config, cb) => {
const minPostFix = options && options.minify ? '.umd.min' : '.umd';
const fileName = `${name}${minPostFix}.js`;
const dest = path.resolve(__dirname, targetFolder, fileName);
const builder = new Builder();
console.log('Bundling system.js file:', fileName, options);
builder.config(config);
return builder
.buildStatic('dist/index', dest, {format: 'umd'})
.then(() => {
console.log('Build complete.');
cb();
})
.catch(err => {
console.log('Error', err);
cb();
});
};
}