Skip to content

Commit

Permalink
feat(build): system.js bundles replaced with UMD bundles
Browse files Browse the repository at this point in the history
BREAKIN CHANGES:
- please read sample repo readme.md to update you system.js config
https://github.com/valor-software/angular2-quickstart
  • Loading branch information
valorkin committed Oct 11, 2016
1 parent a7554a8 commit 3e0a27d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 152 deletions.
113 changes: 0 additions & 113 deletions .config/bundle-system.js

This file was deleted.

88 changes: 88 additions & 0 deletions .config/umd-bundler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/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'
},
paths: {
'*': '*.js'
},
meta: {
'./node_modules/@angular/*': {build: false},
'./node_modules/rxjs/*': {build: false},
moment: {build: false}
}
};

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(name, dest, {format: 'umd'})
.then(() => {
console.log('Build complete.');
cb();
})
.catch(err => {
console.log('Error', err);
cb();
});
};
}
37 changes: 0 additions & 37 deletions make.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"flow.docs": "npm run typedoc -- --exclude '**/*.spec.ts' ./components/",
"flow.compile": "npm run flow.compile:common && npm run flow.compile:system",
"flow.compile:common": "ngc -p tsconfig.publish.json",
"flow.compile:system": "node ./.config/bundle-system.js",
"flow.compile:system": "node .config/umd-bundler.js",
"flow.copy:src": "cpy ng2-bootstrap.ts \"components/*.ts\" ts --parents",
"flow.clean": "del-cli bundles coverage demo-build \"components/**/*.+(js|d.ts|js.map|metadata.json)\" dist \"ng2-bootstrap.+(js|d.ts|js.map|metadata.json)\" factories",
"flow.deploy:gh-pages": "npm run flow.build:prod && gh-pages -d demo-build",
Expand All @@ -30,7 +30,8 @@
"version": "npm run flow.changelog && git add -A",
"postversion": "git push origin development && git push --tags"
},
"main": "ng2-bootstrap.js",
"main": "bundles/ng2-bootstrap.js",
"module": "ng2-bootstrap.js",
"typings": "ng2-bootstrap.d.ts",
"keywords": [
"angular2",
Expand Down

0 comments on commit 3e0a27d

Please sign in to comment.