Angular 2 开发环境搭建

目录结构如下

这里写图片描述

文件说明

gulp.config.js
module.exports = function() {
    var config = {
        allTs: './app/**/*.ts',
        tsOutputPath: './app/'  
    };

    return config;
}
gulpfile.js
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var tsc = require('gulp-typescript');
var tslint = require('gulp-tslint');
var tsProject = tsc.createProject('tsconfig.json');
var config = require('./gulp.config')();

// var browserSync = require('browser-sync');
var connect = require('gulp-connect');
var superstatic = require('superstatic');

gulp.task('ts-lint', function() {
    return gulp.src(config.allTs)
        .pipe(tslint())
        .pipe(tslint.report('prose', {
            emitError: false
        }));
})

gulp.task('compile-ts', function() {
    var sourceTsFiles = [
        config.allTs
    ];

    var tsResult = gulp
        .src(sourceTsFiles)
        .pipe(sourcemaps.init())
        .pipe(tsc(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(config.tsOutputPath));
});

gulp.task('server',function(){
    connect.server({
        basename:[__dirname],
        port:3000,
        livereload:true
    });
});

gulp.task('reload',function(){
    gulp.src('./*.html')
    .pipe(connect.reload());
});

gulp.task('default', ['server'],function(){
    gulp.watch([config.allTs], ['ts-lint', 'compile-ts']);
    gulp.watch(['./app/*.map'],['reload']);
});
index.html
<html>
  <head>
    <base href="/">
    <title>Angular 2 - ToDo App</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script>
      System.config({
        defaultJSExtensions: true,
        map: {
          "angular2-jwt": "node_modules/angular2-jwt/angular2-jwt",
          "angular2": "node_modules/angular2",
          "rxjs": "node_modules/rxjs"
        }
      });
      System.import('app/boot').then(null, console.error.bind(console));
    </script>
  </head>
  <body>
    <hello-world>Loading...</hello-world>
  </body>
</html>
package.json
{
  "name": "asdad",
  "version": "0.0.1",
  "description": "asd",
  "main": "ad",
  "scripts": {
    "test": "ad"
  },
  "repository": {
    "type": "git",
    "url": "asd"
  },
  "keywords": [
    "aad"
  ],
  "author": "ada",
  "license": "MIT",
  "devDependencies": {
    "angular2": "2.0.0-beta.0",
    "angular2-jwt": "^0.1.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "gulp": "^3.9.0",
    "gulp-connect": "^2.3.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-tslint": "^4.3.1",
    "gulp-typescript": "^2.10.0",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "superstatic": "^4.0.1",
    "systemjs": "0.19.6",
    "zone.js": "0.5.10"
  }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}
tslint.json
{
  "rules": {
    "class-name": true,
    "curly": true,
    "eofline": false,
    "forin": true,
    "indent": [true, 4],
    "label-position": true,
    "label-undefined": true,
    "max-line-length": [true, 140],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-key": true,
    "no-duplicate-variable": true,
    "no-empty": true,
    "no-eval": true,
    "no-imports": true,
    "no-string-literal": false,
    "no-trailing-comma": true,
    "no-trailing-whitespace": true,
    "no-unused-variable": false,
    "no-unreachable": true,
    "no-use-before-declare": true,
    "one-line": [true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "quotemark": [true, "single"],
    "radix": true,
    "semicolon": true,
    "triple-equals": [true, "allow-null-check"],
    "variable-name": false,
    "whitespace": [true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator"
    ]
  }
}
执行

1、npm install
2、gulp

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值