Skip to content

Commit 3e43c17

Browse files
committed
chore(angular2): move to rollup + closure compiler
1 parent 0c66b94 commit 3e43c17

File tree

13 files changed

+116
-144
lines changed

13 files changed

+116
-144
lines changed

angular-v2.0.0/config/helpers.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

angular-v2.0.0/config/webpack.common.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

angular-v2.0.0/config/webpack.dev.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

angular-v2.0.0/config/webpack.prod.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

angular-v2.0.0/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<body>
1010
<body>
1111
<my-app></my-app>
12-
<script type="text/javascript" src="dist/polyfills.js"></script>
13-
<script type="text/javascript" src="dist/app.js"></script>
12+
<script type="text/javascript" src="dist/main.aot.js"></script>
1413
</body>
1514
</html>

angular-v2.0.0/package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"version": "1.0.0",
44
"description": "A webpack starter for angular 2",
55
"scripts": {
6-
"start": "webpack-dev-server --inline --progress --port 8080 --config config/webpack.dev.js",
6+
"start": "npm run build-dev && npm run serve",
77
"test": "karma start",
88
"precompile": "ngc",
9-
"build-prod": "npm run precompile && webpack --config config/webpack.prod.js --progress --profile --bail",
10-
"build-dev": "webpack -w -d --config config/webpack.dev.js --progress --profile --bail",
9+
"build-prod": "npm run precompile && node rollup.config.js --prod",
10+
"build-dev": "npm run precompile && node rollup.config.js",
11+
"serve": "http-server",
1112
"postinstall": "typings install"
1213
},
1314
"license": "MIT",
@@ -24,14 +25,11 @@
2425
"zone.js": "0.6.23"
2526
},
2627
"devDependencies": {
27-
"rollup": "^0.35.11",
28-
"rollup-plugin-commonjs": "^5.0.3",
28+
"google-closure-compiler-js": "^20160916.0.0",
29+
"http-server": "^0.9.0",
30+
"rollup": "^0.35.15",
31+
"rollup-plugin-commonjs": "^5.0.4",
2932
"rollup-plugin-node-resolve": "^2.0.0",
30-
"ts-loader": "^0.8.2",
31-
"typescript": "2.0.2",
32-
"typings": "^1.3.3",
33-
"webpack": "^2.1.0-beta.22",
34-
"webpack-dev-server": "^1.15.0",
35-
"webpack-merge": "^0.14.1"
33+
"typescript": "2.0.2"
3634
}
3735
}

angular-v2.0.0/rollup.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var rollup = require( 'rollup' );
2+
var nodeResolve = require('rollup-plugin-node-resolve');
3+
var commonJS = require('rollup-plugin-commonjs');
4+
var closure = require('google-closure-compiler-js');
5+
var argv = require('yargs').argv;
6+
7+
//simple closure compiler wrapper for rollup
8+
function closureCompilerPlugin(options = {}){
9+
return {
10+
transformBundle(bundle){
11+
const compilation = Object.assign({}, options, {
12+
jsCode: options.jsCode ? options.jsCode.concat({ src: bundle }) : [{ src: bundle }]
13+
});
14+
console.log('closure compiler optimizing...');
15+
const transformed = closure.compile(compilation);
16+
console.log('closure compiler optimizing complete');
17+
return { code: transformed.compiledCode, map: transformed.sourceMap };
18+
}
19+
}
20+
}
21+
22+
var writeIIFE = fileName => bundle => bundle.write({format: 'iife', dest: fileName});
23+
24+
//rollup plugins
25+
var plugins = [
26+
nodeResolve({ module: true }),
27+
commonJS(),
28+
]
29+
30+
//only do closure in prod mode (slow!)
31+
if(argv.prod){
32+
plugins.push(closureCompilerPlugin({ compilationLevel: 'SIMPLE' }));
33+
}
34+
35+
//build the AOT package
36+
var buildAOT = rollup.rollup({
37+
entry: './lib/main.aot.js',
38+
plugins: plugins
39+
})
40+
.then(writeIIFE('./dist/main.aot.js'))
41+
.catch(err => console.log(err));
42+
43+
//build the JIT package
44+
var buildJIT = rollup.rollup({
45+
entry: './lib/main.jit.js',
46+
plugins: plugins
47+
})
48+
.then(writeIIFE('./dist/main.jit.js'))
49+
.catch(err => console.log(err));
50+
51+
//wait for all to complete
52+
Promise.all([
53+
buildAOT,
54+
buildJIT
55+
])
56+
.then(() => console.log('built angular2'));

angular-v2.0.0/src/app.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="container">
2+
<div class="jumbotron">
3+
<div class="row">
4+
<div class="col-md-6">
5+
<h1>Angular v2.0.0</h1>
6+
</div>
7+
<div class="col-md-6">
8+
<div class="col-sm-6 smallpad">
9+
<button type="button" class="btn btn-primary btn-block" id="run" (click)="run()" ref="text">Create 1,000 rows</button>
10+
</div>
11+
<div class="col-sm-6 smallpad">
12+
<button type="button" class="btn btn-primary btn-block" id="runlots" (click)="runLots()">Create 10,000 rows</button>
13+
</div>
14+
<div class="col-sm-6 smallpad">
15+
<button type="button" class="btn btn-primary btn-block" id="add" (click)="add()" ref="text">Append 1,000 rows</button>
16+
</div>
17+
<div class="col-sm-6 smallpad">
18+
<button type="button" class="btn btn-primary btn-block" id="update" (click)="update()">Update every 10th row</button>
19+
</div>
20+
<div class="col-sm-6 smallpad">
21+
<button type="button" class="btn btn-primary btn-block" id="clear" (click)="clear()">Clear</button>
22+
</div>
23+
<div class="col-sm-6 smallpad">
24+
<button type="button" class="btn btn-primary btn-block" id="swaprows" (click)="swapRows()">Swap Rows</button>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
<table class="table table-hover table-striped test-data">
30+
<tbody>
31+
<tr [class.danger]="item.id === selected" *ngFor="let item of data trackBy itemById">
32+
<td class="col-md-1">{{item.id}}</td>
33+
<td class="col-md-4">
34+
<a href="#" (click)="select(item, $event)">{{item.label}}</a>
35+
</td>
36+
<td class="col-md-1"><a href="#" (click)="delete(item, $event)"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
37+
<td class="col-md-6"></td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
42+
</div>

angular-v2.0.0/src/app.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,7 @@ let stopMeasure = function() {
2727

2828
@Component({
2929
selector: 'my-app',
30-
template: `
31-
<div class="container">
32-
<div class="jumbotron">
33-
<div class="row">
34-
<div class="col-md-6">
35-
<h1>Angular v2.0.0</h1>
36-
</div>
37-
<div class="col-md-6">
38-
<div class="col-sm-6 smallpad">
39-
<button type="button" class="btn btn-primary btn-block" id="run" (click)="run()" ref="text">Create 1,000 rows</button>
40-
</div>
41-
<div class="col-sm-6 smallpad">
42-
<button type="button" class="btn btn-primary btn-block" id="runlots" (click)="runLots()">Create 10,000 rows</button>
43-
</div>
44-
<div class="col-sm-6 smallpad">
45-
<button type="button" class="btn btn-primary btn-block" id="add" (click)="add()" ref="text">Append 1,000 rows</button>
46-
</div>
47-
<div class="col-sm-6 smallpad">
48-
<button type="button" class="btn btn-primary btn-block" id="update" (click)="update()">Update every 10th row</button>
49-
</div>
50-
<div class="col-sm-6 smallpad">
51-
<button type="button" class="btn btn-primary btn-block" id="clear" (click)="clear()">Clear</button>
52-
</div>
53-
<div class="col-sm-6 smallpad">
54-
<button type="button" class="btn btn-primary btn-block" id="swaprows" (click)="swapRows()">Swap Rows</button>
55-
</div>
56-
</div>
57-
</div>
58-
</div>
59-
<table class="table table-hover table-striped test-data">
60-
<tbody>
61-
<tr [class.danger]="item.id === selected" *ngFor="let item of data trackBy itemById">
62-
<td class="col-md-1">{{item.id}}</td>
63-
<td class="col-md-4">
64-
<a href="#" (click)="select(item, $event)">{{item.label}}</a>
65-
</td>
66-
<td class="col-md-1"><a href="#" (click)="delete(item, $event)"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
67-
<td class="col-md-6"></td>
68-
</tr>
69-
</tbody>
70-
</table>
71-
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
72-
</div>
73-
`
30+
templateUrl: './app.html'
7431
})
7532
export class App implements AfterViewChecked {
7633
data: Array<Data> = [];

angular-v2.0.0/src/main.aot.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
import 'zone.js/dist/zone';
12
import { platformBrowser } from '@angular/platform-browser';
23
import { enableProdMode } from '@angular/core';
34
import { AppModuleNgFactory } from './app.ngfactory';
4-
if (process.env.ENV === 'production') {
5-
console.log("enable prod mode");
6-
enableProdMode();
7-
}
5+
enableProdMode();
86
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);

0 commit comments

Comments
 (0)