|
2 | 2 |
|
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | | -/*eslint no-console: 0, no-sync: 0*/ |
6 | | - |
7 | | -// UMD bundler |
8 | | -// simple and yet reusable system.js bundler |
9 | | -// bundles, minifies and gzips |
10 | | - |
11 | | -const fs = require('fs'); |
12 | 5 | const del = require('del'); |
13 | 6 | const path = require('path'); |
14 | | -const zlib = require('zlib'); |
15 | | -const async = require('async'); |
16 | 7 | const Builder = require('systemjs-builder'); |
17 | 8 |
|
18 | 9 | const pkg = require('./package.json'); |
19 | | -const name = pkg.name; |
20 | | -const targetFolder = path.resolve('./bundles'); |
| 10 | +const targetFolder = path.resolve('./dist/bundles'); |
| 11 | + |
| 12 | +del(targetFolder) |
| 13 | + .then(paths => { |
| 14 | + console.log('Deleted files and folders:\n', paths.join('\n')); |
| 15 | + }) |
| 16 | + .then(() => { |
| 17 | + const systemJsConfig = { minify: false, sourceMaps: true, mangle: false, noEmitHelpers: false, declaration: false }; |
| 18 | + return Promise.all([ |
| 19 | + buildSystemJs(systemJsConfig), |
| 20 | + buildSystemJs(Object.assign({}, systemJsConfig, {minify: true})) |
| 21 | + ]); |
| 22 | + }) |
| 23 | + .catch(e => console.log(e)); |
21 | 24 |
|
22 | | -async.waterfall([ |
23 | | - cleanBundlesFolder, |
24 | | - getSystemJsBundleConfig, |
25 | | - buildSystemJs({minify: false, sourceMaps: true, mangle: false, noEmitHelpers: false, declaration: true}), |
26 | | - getSystemJsBundleConfig, |
27 | | - buildSystemJs({minify: true, sourceMaps: true, mangle: false, noEmitHelpers: false, declaration: true}) |
28 | | -], err => { |
29 | | - if (err) { |
30 | | - throw err; |
31 | | - } |
32 | | -}); |
| 25 | +function buildSystemJs(options) { |
| 26 | + const minPostFix = options && options.minify ? '.umd.min' : '.umd'; |
| 27 | + const fileName = `${pkg.name}${minPostFix}.js`; |
| 28 | + const dest = path.resolve(__dirname, targetFolder, fileName); |
| 29 | + const builder = new Builder(); |
| 30 | + |
| 31 | + console.log('Bundling system.js file:', fileName, options); |
| 32 | + builder.config(getSystemJsBundleConfig()); |
| 33 | + |
| 34 | + return builder |
| 35 | + .buildStatic('dist/index', dest, { format: 'umd' }) |
| 36 | + .then((b) => { |
| 37 | + console.log(`Build complete: ${minPostFix}`); |
| 38 | + }) |
| 39 | + .catch(err => { |
| 40 | + console.log('Error', err); |
| 41 | + }); |
| 42 | +} |
33 | 43 |
|
34 | | -function getSystemJsBundleConfig(cb) { |
35 | | - const config = { |
| 44 | +function getSystemJsBundleConfig() { |
| 45 | + return { |
36 | 46 | baseURL: '.', |
37 | | - transpiler: 'typescript', |
38 | | - typescriptOptions: { |
39 | | - module: 'cjs' |
40 | | - }, |
41 | 47 | map: { |
42 | | - typescript: './node_modules/typescript/lib/typescript', |
| 48 | + typescript: './node_modules/typescript/lib/typescript.js', |
43 | 49 | '@angular': './node_modules/@angular', |
44 | 50 | rxjs: './node_modules/rxjs/bundles', |
45 | | - lodash: './node_modules/lodash' |
| 51 | + 'lodash-es': './node_modules/lodash-es' |
46 | 52 | }, |
47 | 53 | paths: { |
48 | | - '*': '*.js', |
| 54 | + '*': '*.js' |
49 | 55 | }, |
50 | 56 | meta: { |
51 | | - './node_modules/@angular/*': {build: false}, |
52 | | - './node_modules/rxjs/*': {build: false}, |
53 | | - lodash: {build: false, main: 'lodash.js'} |
| 57 | + './node_modules/@angular/*': { build: false }, |
| 58 | + './node_modules/rxjs/*': { build: false } |
54 | 59 | } |
55 | 60 | }; |
56 | | - |
57 | | - return cb(null, config); |
58 | | -} |
59 | | - |
60 | | -function cleanBundlesFolder(cb) { |
61 | | - return del(targetFolder) |
62 | | - .then(paths => { |
63 | | - console.log('Deleted files and folders:\n', paths.join('\n')); |
64 | | - cb(); |
65 | | - }); |
66 | | -} |
67 | | - |
68 | | -function buildSystemJs(options) { |
69 | | - return (config, cb) => { |
70 | | - const minPostFix = options && options.minify ? '.umd.min' : '.umd'; |
71 | | - const fileName = `${name}${minPostFix}.js`; |
72 | | - const dest = path.resolve(__dirname, targetFolder, fileName); |
73 | | - const builder = new Builder(); |
74 | | - |
75 | | - console.log('Bundling system.js file:', fileName, options); |
76 | | - builder.config(config); |
77 | | - |
78 | | - return builder |
79 | | - .buildStatic('dist/index', dest, {format: 'umd'}) |
80 | | - .then(() => { |
81 | | - console.log('Build complete.'); |
82 | | - cb(); |
83 | | - }) |
84 | | - .catch(err => { |
85 | | - console.log('Error', err); |
86 | | - cb(); |
87 | | - }); |
88 | | - }; |
89 | 61 | } |
0 commit comments