: - Angular 4, , SSR , . https://www.nuget.org/packages/Microsoft.AspNetCore.SpaTemplates
: , , . , .NET Core, Angular 4, HMR Webpack, Angular SPA, Angular 2.
.
dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
dotnet new angular
( https://jonhilton.net/2017/02/21/create-a-vs2017-angular-2-and-net-core-site-using-the-command-line/)
, , Angular 2 Universal Server Side Rendering Angular 4.
webpack.config.vendor.js
angular2 -universal
angular2 -
BundleConfig
:
new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')),
:
new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, path.join(__dirname, './ClientApp')),
webpack.config.js
serverBundleConfig
package.json
angular/animation, core-js, es6-prom
Angular 4.0.0
angular2 -universal, angular2 -universal-patch, angular2 - ,
Views/Home/Index.cshtml
asp-prerender-module = "ClientApp/dist/main-server"
ClientApp/polyfills/polyfills.ts
:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js';
ClientApp/ server.ts
ClientApp/ client.ts
:
import './polyfills/polyfills.ts';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
const rootElemTagName = 'app';
if (module['hot']) {
module['hot'].accept();
module['hot'].dispose(() => {
const oldRootElem = document.querySelector(rootElemTagName);
const newRootElem = document.createElement(rootElemTagName);
oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem);
platform.destroy();
});
} else {
enableProdMode();
}
const platform = platformBrowserDynamic();
const bootApplication = () => { platform.bootstrapModule(AppModule); };
if (document.readyState === 'complete') {
bootApplication();
} else {
document.addEventListener('DOMContentLoaded', bootApplication);
}
ClientApp//app.module.ts
UniversalModule :
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
UniversalModule :
BrowserModule,
HttpModule,
, :
npm prune
npm install
webpack --config webpack.config.vendor.js
( https://github.com/aspnet/JavaScriptServices/issues/938)
, Angular 4, .NET, HMR Webpack.