-
Notifications
You must be signed in to change notification settings - Fork 189
/
umd-bundler.js
68 lines (60 loc) · 1.64 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
#!/usr/bin/env node
'use strict';
const del = require('del');
const path = require('path');
const Builder = require('systemjs-builder');
const pkg = require('./package.json');
const targetFolder = path.resolve('./dist/bundles');
del(targetFolder)
.then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
})
.then(() => {
return Promise.all([
buildSystemJs(),
buildSystemJs({minify: true})
]);
})
.catch(e => console.log(e));
function buildSystemJs(options = {}) {
const minPostFix = options && options.minify ? '.umd.min' : '.umd';
const fileName = `${pkg.name}${minPostFix}.js`;
const dest = path.resolve(__dirname, targetFolder, fileName);
const builder = new Builder();
console.log('Bundling system.js file:', fileName, options);
builder.config(getSystemJsBundleConfig());
return builder
.buildStatic('dist/index', dest, Object.assign({
format: 'umd',
minify: false,
sourceMaps: true,
mangle: false,
noEmitHelpers: false,
declaration: false
}, options))
.then((b) => {
console.log(`Build complete: ${minPostFix}`);
})
.catch(err => {
console.log('Error', err);
});
}
function getSystemJsBundleConfig() {
return {
baseURL: '.',
map: {
typescript: './node_modules/typescript/lib/typescript.js',
'@angular': './node_modules/@angular',
rxjs: './node_modules/rxjs/bundles',
uuid: './node_modules/uuid',
crypto: '@empty'
},
paths: {
'*': '*.js'
},
meta: {
'./node_modules/@angular/*': { build: false },
'./node_modules/rxjs/*': { build: false }
}
};
}