欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解webpack+angular2開發(fā)環(huán)境搭建

 更新時間:2017年06月28日 11:21:05   作者:追逐前沿的攻城獅  
這篇文章主要介紹了詳解webpack+angular2開發(fā)環(huán)境搭建,具有一定的參考價值,感興趣的小伙伴們可以參考一下

剛搭建完一個webpack+angular2環(huán)境,由于angular及webpack官網(wǎng)上沒有一個折中的搭建方案,所以只能摸索著搭建,中間遇到一些坑,遂總結(jié)記錄下來,以供交流。

搭建完后的項目初步環(huán)境如下:

app
----app.component.ts
----app.module.ts
----main.ts
index.html
package.json
tsconfig.json
webpack.config.js

app.componnet.ts:組件文件。angular2應(yīng)用是由組件構(gòu)成,組件控制視圖;

import { Component } from '@angular/core';
@Component({
 selector: 'my-app',
 template: `
  <h1>{{title}}</h1>
  <h2>My favorite hero is: {{myHero}}</h2>
  `
})
// 使用變量初始化方式
export class AppComponent {
 title = 'Tour of Heroes';
 myHero = 'Windstorm';
}

app.module.ts:應(yīng)用跟模塊。angular是模塊化,擁有自己的模塊系統(tǒng),被稱為angular模塊或NgModules(深入了解);//缺少下述模塊引入,會輸出"Uncaught reflect-metadata shim is required when using class decorators"的錯誤

import 'core-js/es6';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
//引入NgModule裝飾器
import { NgModule }   from '@angular/core';
//引入瀏覽器模塊
import { BrowserModule } from '@angular/platform-browser';
//引入創(chuàng)建的component
import { AppComponent } from './app.component';


@NgModule({
 imports:   [ BrowserModule ],
 declarations: [ AppComponent ],
 bootstrap:  [ AppComponent ]
})
export class AppModule { }

 main.ts:用于引導跟模塊啟動應(yīng)用;

 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
 import { AppModule }       from './app.module';
 //引導跟模塊啟動應(yīng)用
platformBrowserDynamic().bootstrapModule(AppModule);

index.html:angular應(yīng)用宿主頁面;
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width" />
  <title>small胖的博客</title>
</head>
<body>
  <my-app></my-app>
  <script src="dist/bundle.js"></script>
</body>
</html>

package.json:一個標準化的npm說明文件,其中包含諸如當前應(yīng)用的依賴包、自定義的腳本命令等,在cmd終端可用npm init自動創(chuàng)建該文件;

注意,此處如果引入的angular模塊版本是2.4.X,則會報錯“Angular2 + Jspm.io : reflect-metadata shim is required when using class decorators”,產(chǎn)生此坑的具體原因尚不清楚,希望有朋友一起交流。

{
 "name": "blogcode",
 "version": "1.0.0",
 "description": "",
 "main": "webpack.config.js",
 "dependencies": {
  "ts-loader": "2.0.0",
  "@angular/common": "2.1.2",
  "@angular/compiler": "2.1.2",
  "@angular/core": "2.1.2",
  "@angular/platform-browser": "2.1.2",
  "@angular/platform-browser-dynamic":"2.1.2",
  "rxjs": "5.0.0-beta.12",
  "zone.js": "0.6.26",
  "core-js": "^2.4.1"
 },
 "devDependencies": {
  "webpack": "^2.2.1",
  "@types/core-js": "^0.9.35",
  "typescript": "^2.1.5",
  "webpack": "^2.2.0",
  "webpack-dev-server": "^2.3.0"
 },
 "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
 },
 "repository": {
  "type": "git",
  "url": "https://git.coding.net/frankshin/xudengwei.git"
 },
 "author": "",
 "license": "ISC"
}

tsconfig.json:用于定義typescript編譯成ES5的各項參數(shù);

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "declaration": false
  },
  "buildOnSave": false,
  "compileOnSave": false,
  "exclude": [
    "node_modules"
  ]
}

webpack.config.js:一個標準化的commonjs文件,用于配置webpack編譯打包的參數(shù)。

module.exports = {
  entry: "./app/main.ts",
  output: {
    path: __dirname + '/dist',
    filename: "bundle.js"
  },
  module: {
  rules: [
    {
     test: /\.tsx?$/,
     loader: 'ts-loader',
     exclude: /node_modules/,
    },
  ]
  },
  resolve: {
   extensions: [".tsx", ".ts", ".js"]
  }
};

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • AngulaJS路由 ui-router 傳參實例

    AngulaJS路由 ui-router 傳參實例

    本篇文章主要介紹了AngulaJS路由 ui-router 傳參實例 ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • angularjs中的單元測試實例

    angularjs中的單元測試實例

    這篇文章主要介紹了angularjs中的單元測試實例,本文主要說說利用karma和jasmine來進行ng模塊的單元測試,需要的朋友可以參考下
    2014-12-12
  • Angular2表單自定義驗證器的實現(xiàn)

    Angular2表單自定義驗證器的實現(xiàn)

    本文給大家介紹angular2表單自定義驗證器的實現(xiàn),本文給大家介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-10-10
  • AngularJS ng-template寄宿方式用法分析

    AngularJS ng-template寄宿方式用法分析

    這篇文章主要介紹了AngularJS ng-template寄宿方式用法,結(jié)合實例形式分析了ng-template模板的相關(guān)使用技巧,需要的朋友可以參考下
    2016-11-11
  • angular2 組件之間通過service互相傳遞的實例

    angular2 組件之間通過service互相傳遞的實例

    今天小編就為大家分享一篇angular2 組件之間通過service互相傳遞的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • 深入理解Angular.JS中的Scope繼承

    深入理解Angular.JS中的Scope繼承

    這篇文章主要給大家深入的介紹了關(guān)于Angular.JS中Scope繼承的相關(guān)資料,Angular。JS中scope之間的繼承關(guān)系使用JavaScript的原型繼承方式實現(xiàn),文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • AngularJS實現(xiàn)星星等級評分功能

    AngularJS實現(xiàn)星星等級評分功能

    這篇文章主要為大家詳細介紹了AngularJS實現(xiàn)星星等級評分功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解Angular2 之 結(jié)構(gòu)型指令

    詳解Angular2 之 結(jié)構(gòu)型指令

    本篇文章主要介紹了詳解Angular2 之 結(jié)構(gòu)型指令,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Angular實現(xiàn)表單驗證功能

    Angular實現(xiàn)表單驗證功能

    這篇文章主要為大家詳細介紹了Angular實現(xiàn)表單驗證功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 高效利用Angular中內(nèi)置服務(wù)$http、$location等

    高效利用Angular中內(nèi)置服務(wù)$http、$location等

    這篇文章主要介紹了如何高效利用Angular中內(nèi)置服務(wù),大家知道的Angular內(nèi)置服務(wù)有哪些,感興趣的小伙伴們可以參考一下
    2016-03-03

最新評論