Skip to content

Commit 19d6e62

Browse files
committed
Added DLL plugin and @angularclas/webpack-tool kit for some pun plans to use.
1 parent 8af2018 commit 19d6e62

File tree

5 files changed

+150
-59
lines changed

5 files changed

+150
-59
lines changed

addon/ng2/commands/init.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
77
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
88
var GitInit = require('../tasks/git-init');
99
var LinkCli = require('../tasks/link-cli');
10+
var BuildWebpackDll = require('../tasks/build-webpack-dll');
1011

1112
module.exports = Command.extend({
1213
name: 'init',
@@ -50,6 +51,12 @@ module.exports = Command.extend({
5051
project: this.project
5152
});
5253

54+
var buildWebpackDll = new BuildWebpackDll({
55+
ui: this.ui,
56+
analytics: this.analytics,
57+
project: this.project
58+
});
59+
5360
// needs an explicit check in case it's just 'undefined'
5461
// due to passing of options from 'new' and 'addon'
5562
if (commandOptions.skipGit === false) {
@@ -93,7 +100,7 @@ module.exports = Command.extend({
93100

94101
return Promise.reject(new SilentError(message));
95102
}
96-
103+
97104
var blueprintOpts = {
98105
dryRun: commandOptions.dryRun,
99106
blueprint: commandOptions.blueprint || this._defaultBlueprint(),
@@ -141,6 +148,12 @@ module.exports = Command.extend({
141148
verbose: commandOptions.verbose
142149
});
143150
}
151+
})
152+
.then(function() {
153+
return buildWebpackDll.run({
154+
verbose: commandOptions.verbose,
155+
optional: false
156+
})
144157
});
145158
}
146159
});

addon/ng2/models/webpack-build-dll.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
var webpack = require('webpack');
3+
var path = require('path');
4+
5+
6+
// Webpack Config
7+
var webpackConfig = {
8+
devtool: "#source-map",
9+
entry: {
10+
'angular2polyfills': [
11+
'ie-shim',
12+
'core-js/es6/symbol',
13+
'core-js/es6/object',
14+
'core-js/es6/function',
15+
'core-js/es6/parse-int',
16+
'core-js/es6/parse-float',
17+
'core-js/es6/number',
18+
'core-js/es6/math',
19+
'core-js/es6/string',
20+
'core-js/es6/date',
21+
'core-js/es6/array',
22+
'core-js/es6/regexp',
23+
'core-js/es6/map',
24+
'core-js/es6/set',
25+
'core-js/es6/weak-map',
26+
'core-js/es6/weak-set',
27+
'core-js/es6/typed',
28+
'core-js/es6/reflect',
29+
// 'core-js/es6/promise', // problem with firefox
30+
'core-js/es7/reflect',
31+
'zone.js/dist/zone',
32+
'zone.js/dist/long-stack-trace-zone',
33+
],
34+
'angular2vendor': [
35+
'@angular/platform-browser',
36+
'@angular/platform-browser-dynamic',
37+
'@angular/core',
38+
'@angular/common',
39+
'@angular/forms',
40+
'@angular/http',
41+
'@angular/router',
42+
]
43+
},
44+
45+
output: {
46+
path: './dist',
47+
filename: 'dll.[name].[hash].bundle.js',
48+
sourceMapFilename: '[name].map',
49+
chunkFilename: '[id].chunk.js',
50+
library: '__DLL_[name]',
51+
},
52+
53+
54+
plugins: [
55+
new webpack.DllPlugin({
56+
name: '[vendor]',
57+
path: 'dist/vendor-manifest.json',
58+
}),
59+
new webpack.DllPlugin({
60+
name: 'polyfills',
61+
path: 'dist/polyfills-manifest.json',
62+
}),
63+
],
64+
65+
module: {
66+
preLoaders: [
67+
{
68+
test: /\.js$/,
69+
loader: 'source-map-loader',
70+
exclude: [
71+
// these packages have problems with their sourcemaps
72+
path.resolve(__dirname, 'node_modules', 'rxjs'),
73+
path.resolve(__dirname, 'node_modules', '@angular'),
74+
path.resolve(__dirname, 'node_modules', '@ngrx'),
75+
path.resolve(__dirname, 'node_modules', '@angular2-material'),
76+
]
77+
}
78+
79+
],
80+
loaders: [
81+
]
82+
},
83+
84+
node: {
85+
global: 'window',
86+
crypto: 'empty',
87+
module: false,
88+
clearImmediate: false,
89+
setImmediate: false
90+
}
91+
92+
};

addon/ng2/models/webpack-build-vendors.ts

-58
This file was deleted.

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

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as Promise from 'ember-cli/lib/ext/promise';
2+
import * as Task from 'ember-cli/lib/models/task';
3+
import * as chalk from 'chalk';
4+
import * as webpack from 'webpack';
5+
import * as webpackToolkit from '@angularclass/webpack-toolkit';
6+
7+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
8+
const config = webpackToolkit.webpackConfig;
9+
10+
let lastHash: any = null;
11+
module.exports = Task.extend({
12+
run: (runTaskOptions: ServeTaskOptions) => {
13+
let ui = this.ui;
14+
let config = webpackDllConfi
15+
16+
const webpackCompiler = webpack(config);
17+
18+
webpackCompiler.apply(new ProgressPlugin({
19+
profile: true
20+
}));
21+
22+
return new Promise((resolve, reject) => {
23+
webpackCompiler.run((err, stats) => {
24+
// Don't keep cache
25+
// TODO: Make conditional if using --watch
26+
webpackCompiler.purgeInputFileSystem();
27+
28+
if(err) {
29+
lastHash = null;
30+
console.error(err.stack || err);
31+
if(err.details) console.error(err.details);
32+
reject(err.details);
33+
}
34+
35+
if(stats.hash !== lastHash) {
36+
lastHash = stats.hash;
37+
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
38+
}
39+
resolve();
40+
});
41+
});
42+
}
43+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"homepage": "https://github.com/angular/angular-cli",
3232
"dependencies": {
3333
"@angular/compiler-cli": "^0.2.0",
34+
"@angularclass/webpack-toolkit": "^1.0.1",
3435
"@types/webpack": "^1.12.22-alpha",
3536
"angular2-template-loader": "^0.4.0",
3637
"awesome-typescript-loader": "^2.0.0-rc.3",

0 commit comments

Comments
 (0)