From 18109614603b3bef9daf3f187005a8e1c4ee7085 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 3 Oct 2016 17:48:45 +0200 Subject: [PATCH] chore(): add gulp task to create a systemjs bundle * 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 #913) Closes #913 --- package.json | 1 + tools/gulp/constants.ts | 5 ++++ tools/gulp/gulpfile.ts | 1 + tools/gulp/tasks/bundle.ts | 49 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 tools/gulp/tasks/bundle.ts diff --git a/package.json b/package.json index 90439a252542..bc3d0b90ddd2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tools/gulp/constants.ts b/tools/gulp/constants.ts index 408b44fd14c2..49589269305c 100644 --- a/tools/gulp/constants.ts +++ b/tools/gulp/constants.ts @@ -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' diff --git a/tools/gulp/gulpfile.ts b/tools/gulp/gulpfile.ts index 636fa57715bb..9a0b07fdbc1f 100644 --- a/tools/gulp/gulpfile.ts +++ b/tools/gulp/gulpfile.ts @@ -8,3 +8,4 @@ import './tasks/lint'; import './tasks/release'; import './tasks/serve'; import './tasks/unit-test'; +import './tasks/bundle'; diff --git a/tools/gulp/tasks/bundle.ts b/tools/gulp/tasks/bundle.ts new file mode 100644 index 000000000000..12337f3080a8 --- /dev/null +++ b/tools/gulp/tasks/bundle.ts @@ -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. + }); +});