Skip to content

Commit

Permalink
chore(): add gulp task to create a systemjs bundle
Browse files Browse the repository at this point in the history
* Gulp task to create a bundle, which includes all components and all Angular 2 packages
* Designed to run inside of the Plunker Template
* Task to deploy to firebase (as per angular#913)

Closes angular#913
  • Loading branch information
devversion committed Oct 2, 2016
1 parent bb61928 commit f656bc0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"strip-ansi": "^3.0.0",
"stylelint": "^6.9.0",
"symlink-or-copy": "^1.0.1",
"systemjs-builder": "^0.15.31",
"ts-node": "^0.7.3",
"tslint": "^3.13.0",
"typescript": "^2.0.2",
Expand Down
5 changes: 5 additions & 0 deletions tools/gulp/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export const SOURCE_ROOT = join(PROJECT_ROOT, 'src');
export const DIST_ROOT = join(PROJECT_ROOT, 'dist');
export const DIST_COMPONENTS_ROOT = join(DIST_ROOT, '@angular/material');

export const DIST_BUNDLES_ROOT = join(DIST_ROOT, 'bundles');
export const DIST_BUNDLES_OUTPUT_FILE = join(DIST_BUNDLES_ROOT, 'components.bundle.js');

export const PLUNKER_FIREBASE_NAME = 'material2-plnkr';
export const PLUNKER_FIREBASE_TOKEN = process.env['MATERIAL2_PLNKR_TOKEN'];

export const NPM_VENDOR_FILES = [
'@angular', 'core-js/client', 'hammerjs', 'rxjs', 'systemjs/dist', 'zone.js/dist'
Expand Down
1 change: 1 addition & 0 deletions tools/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ import './tasks/lint';
import './tasks/release';
import './tasks/serve';
import './tasks/unit-test';
import './tasks/bundle';
49 changes: 49 additions & 0 deletions tools/gulp/tasks/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {task} from 'gulp';
import {
DIST_ROOT, PROJECT_ROOT, DIST_BUNDLES_OUTPUT_FILE, DIST_BUNDLES_ROOT,
PLUNKER_FIREBASE_NAME, PLUNKER_FIREBASE_TOKEN
} from '../constants';
import * as path from 'path';

const systemjsBuilder = require('systemjs-builder');
const firebase = require('firebase-tools');

const ANGULAR_PACKAGES = [
'@angular/core/',
'@angular/common',
'@angular/compiler',
'@angular/forms',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
];

task('build:bundle', ['build:components', ':build:devapp:vendor', ':build:devapp:ts'], () => {

const entryPoints = ANGULAR_PACKAGES.concat('@angular/material');
const builder = new systemjsBuilder(path.relative(PROJECT_ROOT, DIST_ROOT));

// Load the SystemJS config of the demo-app, because it already includes all mappings.
builder.loadConfigSync(path.join(DIST_ROOT, 'system-config.js'));

// Create a bundle for all specified entry points.
return builder.bundle(entryPoints.join(' + '), DIST_BUNDLES_OUTPUT_FILE, {
minify: true,
sourceMaps: false
});
});


task('deploy:bundle:plunker', ['build:bundle'], () => {
return firebase.deploy({
firebase: PLUNKER_FIREBASE_NAME,
token: PLUNKER_FIREBASE_TOKEN,
public: path.relative(PROJECT_ROOT, DIST_BUNDLES_ROOT)
}).then(() => {
console.log('Firebase: Successfully deployed bundle to firebase.');
process.exit(0); // Manually exit the process, because the CLI keeps the process alive.
}).catch((error: any) => {
console.error(error.message || error);
process.exit(1); // Manually exit the process, because the CLI keeps the process alive.
});
});

0 comments on commit f656bc0

Please sign in to comment.