Skip to content

Commit de8beea

Browse files
TheLarkInnjohannes.werner
authored and
johannes.werner
committed
build: use webpack for building apps.
This pull request replaces the underlying broccoli build system and then replaces it with webpack as the build and bundler. This will affect the following commands (however the user-level) functionality should go unchanged (besides unimplemented flags which will come after this PR.): ng build (with --env flag and --watch flag supported) ng serve (with --port flag supported) ng test / ng e2e The webpack configuration is blackboxed, and therefore users will not see a webpack.config.js file in their repository. Also this PR will bump the typescript version to 2.0 (beta). Fixes angular#909 angular#1155 angular#882
1 parent 8766494 commit de8beea

File tree

14 files changed

+1210
-10
lines changed

14 files changed

+1210
-10
lines changed

addon/ng2/blueprints/mobile/files/__path__/main-app-shell.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import 'angular2-universal-polyfills';
22
import { provide } from '@angular/core';
33
import { APP_BASE_HREF } from '@angular/common';
44
import { APP_SHELL_BUILD_PROVIDERS } from '@angular/app-shell';
5-
import {
6-
REQUEST_URL,
7-
ORIGIN_URL,
8-
Bootloader,
9-
BootloaderConfig,
10-
AppConfig
5+
import {
6+
REQUEST_URL,
7+
ORIGIN_URL,
8+
Bootloader,
9+
BootloaderConfig,
10+
AppConfig
1111
} from 'angular2-universal';
1212
import { AppComponent } from './app/';
1313

@@ -39,9 +39,9 @@ export function getBootloader() : Bootloader {
3939
return new Bootloader(bootloaderConfig);
4040
}
4141

42-
// The build system will call this function with the bootloader from
42+
// The build system will call this function with the bootloader from
4343
// getBootloader and the contents of the index page
4444
export function serialize(bootloader: Bootloader, template: string) : string {
4545
appConfig.template = template;
4646
return bootloader.serializeApplication(appConfig);
47-
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Typescript emit helpers polyfill
2+
import 'ts-helpers';
3+
4+
import '@angular/core';
5+
import '@angular/common';
6+
import '@angular/compiler';
7+
import '@angular/http';
8+
import '@angular/router';
9+
import '@angular/platform-browser';
10+
import '@angular/platform-browser-dynamic';
11+
12+
<% if(isMobile) { %>
13+
import '@angular/app-shell';
14+
<% } %>
15+
16+
import 'rxjs/add/operator/map';
17+
import 'rxjs/add/operator/mergeMap';

addon/ng2/commands/test.js

Whitespace-only changes.

addon/ng2/models/builder.ts

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
const fs = require('fs-extra');
2+
const existsSync = require('exists-sync');
3+
const path = require('path');
4+
const Promise = require('ember-cli/lib/ext/promise');
5+
const Task = require('ember-cli/lib/models/task');
6+
const SilentError = require('silent-error');
7+
const chalk = require('chalk');
8+
const attemptNeverIndex = require('ember-cli/lib/utilities/attempt-never-index');
9+
const findBuildFile = require('ember-cli/lib/utilities/find-build-file');
10+
const viz = require('broccoli-viz');
11+
const FSMonitor = require('fs-monitor-stack');
12+
const Sync = require('tree-sync');
13+
const mkdirp = require('mkdirp');
14+
15+
let resolve = null;
16+
let promise = new Promise((r) => resolve = r);
17+
18+
19+
20+
21+
var signalsTrapped = false;
22+
var buildCount = 0;
23+
24+
function outputViz(count, result, monitor) {
25+
var processed = viz.process(result.graph);
26+
27+
processed.forEach(function(node) {
28+
node.stats.fs = monitor.statsFor(node);
29+
});
30+
31+
fs.writeFileSync('graph.' + count + '.dot', viz.dot(processed));
32+
fs.writeFileSync('graph.' + count + '.json', JSON.stringify({
33+
summary: {
34+
buildCount: count,
35+
output: result.directory,
36+
totalTime: result.totalTime,
37+
totalNodes: processed.length,
38+
stats: {
39+
fs: monitor.totalStats()
40+
}
41+
},
42+
nodes: processed
43+
}));
44+
}
45+
46+
module.exports = Task.extend({
47+
setupBuilder: function() {
48+
this.environment = this.environment || 'development';
49+
process.env.ANGULAR_ENV = process.env.ANGULAR_ENV || process.env.EMBER_CLI || this.environment;
50+
process.env.EMBER_ENV = process.env.ANGULAR_ENV;
51+
52+
var buildFile = findBuildFile('angular-cli-build.js');
53+
this.tree = buildFile({ project: this.project });
54+
55+
if (webpack) {
56+
console.log('webpack');
57+
} else {
58+
var broccoli = require('ember-cli-broccoli');
59+
this.builder = new broccoli.Builder(this.tree);
60+
}
61+
},
62+
63+
trapSignals: function() {
64+
if (!signalsTrapped) {
65+
process.on('SIGINT', this.onSIGINT.bind(this));
66+
process.on('SIGTERM', this.onSIGTERM.bind(this));
67+
process.on('message', this.onMessage.bind(this));
68+
signalsTrapped = true;
69+
}
70+
},
71+
72+
init: function() {
73+
this.setupBuilder();
74+
this.trapSignals();
75+
},
76+
77+
/**
78+
Determine whether the output path is safe to delete. If the outputPath
79+
appears anywhere in the parents of the project root, the build would
80+
delete the project directory. In this case return `false`, otherwise
81+
return `true`.
82+
*/
83+
canDeleteOutputPath: function(outputPath) {
84+
var rootPathParents = [this.project.root];
85+
var dir = path.dirname(this.project.root);
86+
rootPathParents.push(dir);
87+
while (dir !== path.dirname(dir)) {
88+
dir = path.dirname(dir);
89+
rootPathParents.push(dir);
90+
}
91+
return rootPathParents.indexOf(outputPath) === -1;
92+
},
93+
94+
copyToOutputPath: function(inputPath) {
95+
var outputPath = this.outputPath;
96+
97+
mkdirp.sync(outputPath);
98+
99+
if (!this.canDeleteOutputPath(outputPath)) {
100+
throw new SilentError('Using a build destination path of `' + outputPath + '` is not supported.');
101+
}
102+
103+
var sync = this._sync;
104+
if (sync === undefined) {
105+
this._sync = sync = new Sync(inputPath, path.resolve(this.outputPath));
106+
}
107+
108+
sync.sync();
109+
},
110+
111+
build: function(...args: any[]) {
112+
attemptNeverIndex('tmp');
113+
return promise;
114+
// return Promise.resolve();
115+
// if (this.webpack) {
116+
// console.log(1, process.cwd());
117+
// return new Promise((resolve, reject) => {
118+
// this.webpack.run((err, stats) => {
119+
// console.log(!!err, stats);
120+
// if (err) {
121+
// reject(err);
122+
// }
123+
// resolve();
124+
// });
125+
// });
126+
// }
127+
// return this.builder.build(...args);
128+
},
129+
130+
cleanup: function() {
131+
var ui = this.ui;
132+
133+
// if (this.webpack) {
134+
// this.webpack.cleanupAndExit();
135+
return Promise.resolve();
136+
// } else {
137+
// return this.builder.cleanup().catch(function (err) {
138+
// ui.writeLine(chalk.red('Cleanup error.'));
139+
// ui.writeError(err);
140+
// });
141+
// }
142+
},
143+
144+
cleanupAndExit: function() {
145+
this.cleanup().finally(function() {
146+
process.exit(1);
147+
});
148+
},
149+
150+
onSIGINT: function() {
151+
this.cleanupAndExit();
152+
},
153+
onSIGTERM: function() {
154+
this.cleanupAndExit();
155+
},
156+
onMessage: function(message) {
157+
if (message.kill) {
158+
this.cleanupAndExit();
159+
}
160+
}
161+
});

0 commit comments

Comments
 (0)