Skip to content

Commit 018770d

Browse files
Sean LarkinSean Larkin
Sean Larkin
authored and
Sean Larkin
committed
feat(build) Swapping out build system for Webpack: Implement 3bundles shared and split, along with CLI output and feedback and reporting. And template compilation for inline html and css.
1 parent f1a25c0 commit 018770d

File tree

7 files changed

+94
-33
lines changed

7 files changed

+94
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Prefer CoreJS over the polyfills above
2-
import 'reflect-metadata';
3-
require('zone.js/dist/zone');
4-
5-
// Typescript emit helpers polyfill
6-
import 'ts-helpers';
2+
import 'core-js/es6';
3+
import 'core-js/es7/reflect';
4+
import 'zone.js/dist/zone';
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
{
2-
"compileOnSave": false,
32
"compilerOptions": {
3+
"baseUrl": ".",
44
"declaration": false,
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
77
"module": "es2015",
88
"moduleResolution": "node",
9-
"noEmitOnError": false,
10-
"noImplicitAny": false,
11-
"outDir": "../dist/",
9+
"outDir": "./dist/",
1210
"rootDir": ".",
1311
"sourceMap": true,
14-
"target": "es2015",
15-
"inlineSources": true
16-
}
12+
"sourceRoot": ".",
13+
"target": "es2015"
14+
},
15+
"exclude": [
16+
"node_modules",
17+
"bower_components"
18+
],
19+
"files": [
20+
"./src/typings.d.ts"
21+
]
1722
}

addon/ng2/blueprints/ng2/files/__path__/vendor.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Typescript emit helpers polyfill
2+
import 'ts-helpers';
3+
14
import '@angular/core';
25
import '@angular/common';
36
import '@angular/compiler';

addon/ng2/blueprints/ng2/files/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"@angular/platform-browser": "2.0.0-rc.1",
2121
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
2222
"@angular/router": "2.0.0-rc.1",
23-
"es6-shim": "^0.35.0",
24-
"reflect-metadata": "0.1.3",
2523
"rxjs": "5.0.0-beta.6",
2624
"systemjs": "0.19.26",
25+
"core-js": "^2.4.0",
26+
"ts-helpers": "^1.1.1",
2727
"zone.js": "^0.6.12"
2828
},
2929
"devDependencies": {<% if(isMobile) { %>

addon/ng2/commands/build.ts

+28-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ const win = require('ember-cli/lib/utilities/windows-admin');
88
const webpack = require('webpack');
99
const webpackConfig = require('../tasks/webpack-build-config');
1010
const webpackCompiler = webpack(webpackConfig);
11+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
12+
const webpackOutputOptions = {
13+
colors: true,
14+
chunks: true,
15+
modules: false,
16+
reasons: false,
17+
chunkModules: false
18+
}
19+
20+
let lastHash = null;
21+
22+
webpackCompiler.apply(new ProgressPlugin({
23+
profile: true
24+
}));
25+
1126

1227
module.exports = Command.extend({
1328
name: 'build',
@@ -25,15 +40,22 @@ module.exports = Command.extend({
2540
run: function(commandOptions) {
2641
return new Promise((resolve, reject) => {
2742
webpackCompiler.run((err, stats) => {
28-
debugger;
29-
if (err || stats.compilation.errors.length) {
30-
reject(stats.compilation.errors);
31-
console.log(err);
43+
// Don't keep cache
44+
// TODO: Make conditional if using --watch
45+
webpackCompiler.purgeInputFileSystem();
46+
47+
if(err) {
48+
lastHash = null;
49+
console.error(err.stack || err);
50+
if(err.details) console.error(err.details);
51+
reject(err.details);
3252
}
3353

54+
if(stats.hash !== lastHash) {
55+
lastHash = stats.hash;
56+
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
57+
}
3458
resolve();
35-
console.log(stats);
36-
console.log('--------');
3759
});
3860
});
3961
},

addon/ng2/tasks/webpack-build-config.ts

+39-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const webpack = require('webpack');
22
const HtmlWebpackPlugin = require('html-webpack-plugin');
33
const path = require('path');
44

5+
56
// Resolve to the generated applications
67
function ngAppResolve(resolvePath: string): string {
78
return path.resolve(process.cwd(), resolvePath);
@@ -20,19 +21,40 @@ module.exports = {
2021
},
2122

2223
output: {
23-
path: "./dist",
24-
filename: "[name].bundle.js"
24+
path: './dist',
25+
filename: '[name].bundle.js'
2526
},
2627

2728
module: {
2829
loaders: [
2930
{
3031
test: /\.ts$/,
31-
loader: 'ts-loader'
32+
loaders: [
33+
{
34+
loader: 'awesome-typescript-loader',
35+
query: {
36+
useWebpackText: true,
37+
tsconfig: ngAppResolve('./src/tsconfig.json'),
38+
resolveGlobs: false
39+
}
40+
},
41+
{
42+
loader: 'angular2-template-loader'
43+
}
44+
]
45+
exclude: [/\.(spec|e2e)\.ts$/]
3246
},
3347
{
3448
test: /\.json$/,
3549
loader: 'json-loader'
50+
},
51+
{
52+
test: /\.css$/,
53+
loader: 'raw-loader'
54+
},
55+
{
56+
test: /\.html$/,
57+
loader: 'raw-loader'
3658
}
3759
]
3860
},
@@ -46,22 +68,27 @@ module.exports = {
4668
}),
4769
new webpack.optimize.CommonsChunkPlugin({
4870
name: ['polyfills', 'vendor'].reverse()
71+
}),
72+
new webpack.LoaderOptionsPlugin({
73+
minimize: true
74+
}),
75+
new webpack.LoaderOptionsPlugin({
76+
test: /\.js$/,
77+
jsfile: true
4978
})
5079
],
5180

52-
ts: {
53-
configFileName: ngAppResolve('./src/tsconfig.json'),
54-
silent: true
55-
},
81+
// ts: {
82+
// configFileName: ngAppResolve('./src/tsconfig.json'),
83+
// silent: true
84+
// },
5685

5786
resolve: {
58-
extensions: ['', '.css', '.scss', '.ts', '.js']
87+
extensions: ['', '.ts', '.js'],
88+
root: ngAppResolve('./src')
89+
// modulesDirectories: ['node_modules']
5990
},
6091

61-
devServer: {
62-
historyApiFallback: true
63-
}
64-
6592
node: {
6693
global: 'window',
6794
crypto: 'empty',

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
},
3131
"homepage": "https://github.com/angular/angular-cli",
3232
"dependencies": {
33+
"angular2-template-loader": "^0.2.0",
34+
"awesome-typescript-loader": "^0.19.0",
3335
"broccoli": "^1.0.0-beta.7",
3436
"broccoli-caching-writer": "^2.2.1",
3537
"broccoli-concat": "^2.2.0",
@@ -39,24 +41,28 @@
3941
"broccoli-uglify-js": "^0.1.3",
4042
"broccoli-writer": "^0.1.1",
4143
"chalk": "^1.1.3",
44+
"core-js": "^2.4.0",
4245
"ember-cli": "2.5.0",
4346
"ember-cli-string-utils": "^1.0.0",
4447
"exit": "^0.1.2",
4548
"fs-extra": "^0.30.0",
4649
"glob": "^7.0.3",
4750
"handlebars": "^4.0.5",
51+
"html-webpack-plugin": "^2.19.0",
4852
"json-loader": "^0.5.4",
4953
"leek": "0.0.21",
5054
"lodash": "^4.11.1",
5155
"opn": "4.0.1",
56+
"raw-loader": "^0.5.1",
5257
"resolve": "^1.1.7",
5358
"shelljs": "^0.7.0",
5459
"silent-error": "^1.0.0",
5560
"style-loader": "^0.13.1",
5661
"symlink-or-copy": "^1.0.3",
5762
"systemjs-builder": "0.15.17",
63+
"ts-helpers": "^1.1.1",
5864
"ts-loader": "^0.8.2",
59-
"typescript": "^1.9.0-dev.20160605-1.0",
65+
"typescript": "^1.9.0-dev.20160606-1.0",
6066
"typings": "^0.8.1",
6167
"webpack": "^2.1.0-beta.8"
6268
},

0 commit comments

Comments
 (0)