詳解.Net Core + Angular2 環(huán)境搭建
本文介紹了.Net Core + Angular2 環(huán)境搭建,具體如下:
環(huán)境搭建:
1)node.js版本>5.0,NPM版本>3.0,TypeScript版本>2.0(全裝最新版就好了)
2)安裝NTVS 1.2(node tools for vs),TSVS dev 1.4(TS for VS)
3)構(gòu)建package.json,tsconfig.json,gulp.js文件
1、package.json
{
"name": "template.angular2",
"version": "1.0.0",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/angular/angular.io/blob/master/LICENSE"
}
],
"dependencies": {
"@angular/common": "~2.1.1",
"@angular/compiler": "~2.1.1",
"@angular/core": "~2.1.1",
"@angular/forms": "~2.1.1",
"@angular/http": "~2.1.1",
"@angular/platform-browser": "~2.1.1",
"@angular/platform-browser-dynamic": "~2.1.1",
"@angular/router": "~3.1.1",
"@angular/upgrade": "~2.1.1",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"@types/core-js": "^0.9.34",
"@types/node": "^6.0.45",
"gulp": "^3.9.1",
"del": "^2.2.2"
}
}
2、tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
//需要這個才能使用注釋器
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"compileOnSave": true
}
3、gulp.js
var gulp = require('gulp');
var del = require('del');
var paths = {
angularPatch: [
"node_modules/core-js*/**/*",
"node_modules/zone.js*/**/*",
"node_modules/reflect-metadata*/*.js",
"node_modules/reflect-metadata*/*.map",
"node_modules/systemjs*/dist*/*.js",
"node_modules/systemjs*/dist*/*.map"
],
angularSrc: [
"node_modules/@angular/core/bundles/core.umd.js",
"node_modules/@angular/common/bundles/common.umd.js",
"node_modules/@angular/compiler/bundles/compiler.umd.js",
"node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js",
"node_modules/@angular/http/bundles/http.umd.js",
"node_modules/@angular/router/bundles/router.umd.js",
"node_modules/@angular/forms/bundles/forms.umd.js",
"node_modules/@angular/upgrade/bundles/upgrade.umd.js"
//"node_modules/",
],
rxjsSrc: "node_modules/rxjs/**/*",
TSSrc:"Scripts/**/*.js",
TSTarget:"wwwroot/js",
Tartget:"wwwroot/lib"
}
//手工構(gòu)建一次
gulp.task("copyangularfiles", function () {
//gulp.src(paths.angularSrc).pipe(gulp.dest(paths.Tartget));
paths.angularSrc.forEach(function (path) {
var tpath = path.replace("node_modules", paths.Tartget).split('/');
gulp.src(path).pipe(gulp.dest(tpath.slice(0, tpath.length - 1).join('/')));
});
gulp.src(paths.rxjsSrc).pipe(gulp.dest(paths.Tartget + "/rxjs"));
gulp.src(paths.angularPatch).pipe(gulp.dest(paths.Tartget + "/patch"));
});
//加入任務(wù)->綁定->生成前
gulp.task("copytsfiles", function () {
gulp.src(paths.TSSrc).pipe(gulp.dest(paths.TSTarget));
})
gulp.task('default', ['copytsfiles'], function () {
// place code for your default task here
});
4)在項目根目錄建立 Scripts 文件夾
5)在wwwroot文件夾建立systemjs.config.js
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'lib/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'js',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
6)修改Views/Shared/_Layout.cshtml,刪除對site.js的引用
7)修改Views/Home/Index.cshtml,增加/構(gòu)建@section scripts 腳本段
@section scripts{
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="~/lib/patch/core-js/client/shim.min.js"></script>
<script src="~/lib/patch/zone.js/dist/zone.js"></script>
<script src="~/lib/patch/reflect-metadata/Reflect.js"></script>
<script src="~/lib/patch/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function (err) { console.error(err); });
</script>
}
8)環(huán)境搭建完成,程序入口文件 wwwroot/js/main.js(Scripts/main.ts)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- .Net?Core3.0?WebApi?項目框架搭建之使用Serilog替換掉Log4j
- .Net Core服務(wù)治理Consul搭建集群
- 基于Jenkins搭建.NET Core持續(xù)集成環(huán)境過程圖解
- Centos7系統(tǒng)下搭建.NET Core2.0+Nginx+Supervisor環(huán)境
- CodeFirst從零開始搭建Asp.Net Core2.0網(wǎng)站
- .Net Core+Angular Cli/Angular4開發(fā)環(huán)境搭建教程
- VS2015 搭建Asp.net core開發(fā)環(huán)境的方法
- 云服務(wù)器下搭建ASP.NET Core環(huán)境
- Linux(Ubuntu)下搭建ASP.NET Core環(huán)境
- win10下ASP.NET Core部署環(huán)境搭建步驟
- Windows Server 2012 R2 Standard搭建ASP.NET Core環(huán)境圖文教程
- Ubuntu16.04系統(tǒng)搭建.Net Core開發(fā)環(huán)境
相關(guān)文章
.NET Core讀取配置文件方式詳細(xì)總結(jié)
這篇文章主要為大家詳細(xì)總結(jié)了.NET Core讀取配置文件方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08
.Net Core學(xué)習(xí)教程之在Mvc中簡單的使用日志組件
這篇文章主要給大家介紹了關(guān)于.Net Core學(xué)習(xí)教程之在Mvc中簡單使用日志組件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06
國產(chǎn)化之銀河麒麟安裝.NetCore包管理器方式(步驟詳解)
這篇文章主要介紹了國產(chǎn)化之銀河麒麟安裝.NetCore-包管理器方式,本文給大家分享安裝步驟及安裝命令,對銀河麒麟安裝.NetCore相關(guān)知識感興趣的朋友一起看看吧2022-03-03
asp.net錯誤捕獲(錯誤處理)page_error事件使用方法
Page_Error事件提供了一種捕獲頁面級錯誤的方法。對于錯誤的處理,您可以只是顯示錯誤信息(正如下面的示例代碼所示),也可以記錄事件或執(zhí)行某個其他操作2014-01-01
ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)
把用戶在TextBox輸入的文字創(chuàng)建為一個圖片,ASCX的ImageButton的ImageUrl重新指向這剛產(chǎn)生的圖片,接下來介紹下ASPX向ASCX傳值,感興趣的朋友可以參考下哈2013-03-03
ASP.NET Core中使用MialKit實(shí)現(xiàn)郵件發(fā)送功能
這篇文章主要介紹了ASP.NET Core中使用MialKit實(shí)現(xiàn)郵件發(fā)送功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10

