Skip to content

Commit d102fdb

Browse files
Enable Webpack dev middleware and basic (non-state-preserving) HMR for Angular template
1 parent c1b808f commit d102fdb

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

templates/Angular2Spa/ClientApp/boot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ import { Http, HTTP_PROVIDERS } from 'angular2/http';
77
import { App } from './components/app/app';
88

99
bootstrap(App, [router.ROUTER_BINDINGS, HTTP_PROVIDERS, FormBuilder]);
10+
11+
// Basic hot reloading support. Automatically reloads and restarts the Angular 2 app each time
12+
// you modify source files. This will not preserve any application state other than the URL.
13+
declare var module: any;
14+
if (module.hot) {
15+
module.hot.accept();
16+
}

templates/Angular2Spa/Startup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNet.Builder;
66
using Microsoft.AspNet.Hosting;
7+
using Microsoft.AspNet.SpaServices.Webpack;
78
using Microsoft.Extensions.Configuration;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Logging;
@@ -46,6 +47,14 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
4647
}
4748

4849
app.UseIISPlatformHandler();
50+
51+
if (env.IsDevelopment())
52+
{
53+
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
54+
{
55+
HotModuleReplacement = true
56+
});
57+
}
4958

5059
app.UseStaticFiles();
5160

templates/Angular2Spa/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
"name": "WebApplicationBasic",
33
"version": "0.0.0",
44
"devDependencies": {
5-
"babel-loader": "^6.2.3",
5+
"babel-loader": "^6.2.4",
66
"babel-preset-es2015": "^6.5.0",
77
"babel-preset-react": "^6.5.0",
88
"bootstrap": "^3.3.6",
99
"css-loader": "^0.23.1",
1010
"expose-loader": "^0.7.1",
11+
"express": "^4.13.4",
1112
"extendify": "^1.0.0",
1213
"extract-text-webpack-plugin": "^1.0.1",
1314
"file-loader": "^0.8.5",
1415
"jquery": "^2.2.1",
16+
"ntypescript": "^1.201602282304.1",
1517
"raw-loader": "^0.5.1",
1618
"style-loader": "^0.13.0",
1719
"ts-loader": "^0.8.1",
1820
"typescript": "^1.8.2",
1921
"url-loader": "^0.5.7",
20-
"webpack": "^1.12.14"
22+
"webpack": "^1.12.14",
23+
"webpack-dev-middleware": "^1.5.1",
24+
"webpack-hot-middleware": "^2.7.1"
2125
},
2226
"dependencies": {
2327
"angular2": "^2.0.0-beta.7",

0 commit comments

Comments
 (0)