.Net Core + Angular2 环境搭建

环境搭建:

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)构建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"
}
//手工构建一次
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"));

});
//加入任务->绑定->生成前
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,增加/构建@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)环境搭建完成,程序入口文件 wwwroot/js/main.js(Scripts/main.ts)

时间: 2024-08-02 22:07:21

.Net Core + Angular2 环境搭建的相关文章

angular2 环境搭建

angular2 的环境搭建 第一步:到官网下载nodejs 安装包 安装 第二步:安装好了node  会有npm工具 使用 npm 安装 angular cli 命令:  npm install -g @angular/cli    使用ng -v检测 安装好 之后 可以使用   ng new  项目名 命令创建 一个angular的项目 第三步 :  安装webstorm

.net core运行环境搭建 linux + windows

---------------------------------------linux------------------------------------------------- 一.添加dotnet产品Feed 在安装.NET Core之前,您需要注册Microsoft产品Feed. 这只需要做一次. 首先,注册Microsoft签名密钥,然后添加Microsoft产品Feed. sudo rpm --import https://packages.microsoft.com/keys

.Net Core(一)环境搭建与基本使用

一.系统配置 a) Linux下如果想要打开类似任务管理器,可以使用top命令,在控制台会动态刷新CPU和内存占用.进程等信息.vmstat和free命令可以分别只显示CPU和内存的使用情况.磁盘占用在Ubuntu下可以通过磁盘分析器查看. 另外如果要火狐支持html5视频播放,要在设置中的Content项中勾选DRM. 在vi界面按ctrl+z会挂起vi回到命令行,这时可以输入fg返回. 输入ls -a可以查看被隐藏的文件. 在vi中,在命令模式下按yy可以复制整行,然后在原位置按p可以复制到

angular2环境搭建

Angular2.x与Angular1.x完全不同,Angular2.x是不兼容Angular1.x的,所在在框架的构造上,它们是完全不同的.在Angular2.x中,因为其是基于ES6来开发的,所以会有很多第三方依赖.由于很多浏览器还不支持ES6,所以Angular2引入了很多polyfill或者shim, 导致我们引入了第三方依赖. 官方的说法,它是基于数据流的构建系统(streaming build system),主要用来让自动化和增强你的工作流程(Automate and enhanc

dotNet Core开发环境搭建及简要说明

一.安装 .NET Core SDK 在 Windows 上使用 .NET Core 的最佳途径:使用Visual Studio. 免费下载地址: Visual Studio Community 2015 .下载安装之后 再下载以下两件东西: Visual Studio 2015 Update 3 (这个我安装了一天一夜,国外VPN估计可以解决这个问题) .NET Core 1.0.1 - VS 2015 Tooling Preview 2 当然你也可以使用 .NET Core SDK for

mac上.net core开发环境搭建.md

1. 安装 .NET Core SDK 下载地址:https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install dotnet –info检验SDK是否安装成功: 2. 命令行创建项目 安装好.NET Core SDK后,即可通过命令行创建项目.运行项目,开发也就可以用任意编辑器进行开发了,不过不知道有没有实时编译的功能,否则最好还是用ide,对于代码高亮.语法检测.错误提示.编译.调试会方便很多. dotnet ne

[Step-By-Step Angular2](1)Hello World与自动化环境搭建

随着rc(release candidate,候选版本)版本的推出,万众瞩目的angular2终于离正式发布不远啦!五月初举办的ng-conf大会已经过去了整整一个月,大多数api都如愿保持在了相对稳定的状态——当然也有router这样的例外,在rc阶段还在大面积返工,让人颇为不解——不过总得说来,现在学习angular2不失为一个恰当的时机. Google为angular2准备了完善的文档和教程,按理说,官网(https://angular.io)自然是学习新框架的最好教材.略显遗憾的是,在B

Angular2 快速入门 之 环境搭建

2015.10.14更新:本文的内容已经过期了,Angular2现在已经完全基于TypeScript开发了,可以移步https://github.com/flyingzl/angular2-seed 查看最新代码. 一.题记 写这篇文章呢,主要是想帮助那些想尝鲜Angular2的童鞋们,因为我自己在玩Angular2时碰到了不少坑,而且Angular2语法一直处于变化中,让人很头疼.不过也怪不了Anguar2,因为它现在是处于并长期处于alpha阶段,本文是基于最新的angular2.0.0-a

一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx、supervisor、mysql环境搭建

作为.neter,看到.net core 2.0的正式发布,心里是有点小激动的,迫不及待的体验了一把,发现速度确实是快了很多,其中也遇到一些小问题,所以整理了一些学习笔记: 阅读目录 环境说明 安装CentOS7 安装.NET Core SDK for CentOS7 搭建ftp服务器 安装mysql 部署ASP.NET Core应用程序 配置Nginx 配置守护服务(Supervisor) 环境说明 服务器系统:CentOS 7.3 64位 相关工具:putty.Xftp 服务器软件软件:.n