Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): add gulp task to create a systemjs bundle #1222

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
53 changes: 53 additions & 0 deletions tools/gulp/tasks/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 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'], () => {

// Import the Firebase CLI inside of the task, because the CLI would keep the gulp process alive.
const firebase = require('firebase-tools');

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 firebase CLI keeps the process alive.
}).catch((error: any) => {
console.error(error.message || error);
process.exit(1); // Manually exit the process, because the firebase CLI keeps the process alive.
});

});