
- Angular 2 教程
- Angular 2 - 首頁
- Angular 2 - 概述
- Angular 2 - 環境
- Angular 2 - Hello World
- Angular 2 - 模組
- Angular 2 - 架構
- Angular 2 - 元件
- Angular 2 - 模板
- Angular 2 - 指令
- Angular 2 - 元資料
- Angular 2 - 資料繫結
- 使用 HTTP 進行 CRUD 操作
- Angular 2 - 錯誤處理
- Angular 2 - 路由
- Angular 2 - 導航
- Angular 2 - 表單
- Angular 2 - CLI
- Angular 2 - 依賴注入
- Angular 2 - 高階配置
- Angular 2 - 第三方控制元件
- Angular 2 - 資料顯示
- Angular 2 - 處理事件
- Angular 2 - 資料轉換
- Angular 2 - 自定義管道
- Angular 2 - 使用者輸入
- Angular 2 - 生命週期鉤子
- Angular 2 - 巢狀容器
- Angular 2 - 服務
- Angular 2 有用資源
- Angular 2 - 問題與解答
- Angular 2 - 快速指南
- Angular 2 - 有用資源
- Angular 2 - 討論
Angular 2 - 高階配置
在本章中,我們將瞭解 Angular 2 專案中其他配置文 件。
tsconfig.json
此檔案用於提供有關 Angular JS 專案使用的 TypeScript 的選項。
{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2015", "dom" ], "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true } }
以下是一些關於上述程式碼的關鍵點。
編譯的目標是 es5,這是因為大多數瀏覽器只能理解 ES5 型別指令碼。
sourceMap 選項用於生成對映檔案,這在除錯時非常有用。因此,在開發過程中,最好將此選項保留為 true。
"emitDecoratorMetadata": true 和 "experimentalDecorators": true 是 Angular JS 裝飾器所必需的。如果沒有,Angular JS 應用程式將無法編譯。
package.json
此檔案包含有關 Angular 2 專案的資訊。以下是檔案中 的典型設定。
{ "name": "angular-quickstart", "version": "1.0.0", "description": "QuickStart package.json from the documentation, supplemented with testing support", "scripts": { "build": "tsc -p src/", "build:watch": "tsc -p src/ -w", "build:e2e": "tsc -p e2e/", "serve": "lite-server -c=bs-config.json", "serve:e2e": "lite-server -c=bs-config.e2e.json", "prestart": "npm run build", "start": "concurrently \"npm run build:watch\" \"npm run serve\"", "pree2e": "npm run build:e2e", "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --killothers --success first", "preprotractor": "webdriver-manager update", "protractor": "protractor protractor.config.js", "pretest": "npm run build", "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", "pretest:once": "npm run build", "test:once": "karma start karma.conf.js --single-run", "lint": "tslint ./src/**/*.ts -t verbose" }, "keywords": [], "author": "", "license": "MIT", "dependencies": { "@angular/common": "~2.4.0", "@angular/compiler": "~2.4.0", "@angular/core": "~2.4.0", "@angular/forms": "~2.4.0", "@angular/http": "~2.4.0", "@angular/platform-browser": "~2.4.0", "@angular/platform-browser-dynamic": "~2.4.0", "@angular/router": "~3.4.0", "angular-in-memory-web-api": "~0.2.4", "systemjs": "0.19.40", "core-js": "^2.4.1", "rxjs": "5.0.1", "zone.js": "^0.7.4" }, "devDependencies": { "concurrently": "^3.2.0", "lite-server": "^2.2.2", "typescript": "~2.0.10", "canonical-path": "0.0.2", "tslint": "^3.15.1", "lodash": "^4.16.4", "jasmine-core": "~2.4.1", "karma": "^1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~4.0.14", "rimraf": "^2.5.4", "@types/node": "^6.0.46", "@types/jasmine": "2.5.36" }, "repository": {} }
關於上述程式碼的一些關鍵點 -
依賴項有兩種型別,第一種是依賴項,然後是開發依賴項。開發依賴項在開發過程中需要,其他依賴項需要執行應用程式。
"build:watch": "tsc -p src/ -w" 命令用於透過查詢 TypeScript 檔案中的更改在後臺編譯 TypeScript。
systemjs.config.json
此檔案包含 Angular JS 應用程式所需的系統檔案。這載入所有必要的指令碼檔案,而無需向 html 頁面新增指令碼標籤。典型檔案將包含以下程式碼。
/** * System configuration for Angular samples * Adjust as necessary for your application needs. */ (function (global) { System.config ({ paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { // our app is within the app folder app: 'app', // 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/platformbrowser/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browserdynamic/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', // other libraries 'rxjs': 'npm:rxjs', 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/inmemory-web-api.umd.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { app: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' } } }); })(this);
關於上述程式碼的一些關鍵點 -
'npm:': 'node_modules/' 指示專案中所有 npm 模組所在的 位置。
app: 'app' 的對映指示載入所有應用程式檔案 的資料夾。
廣告