Angular 最佳实践项目教程
angular-best-practices This is a guideline of best practices that you can apply to your Angular project. 项目地址:https://gitcode.com/gh_mirrors/ang/angular-best-practices
1. 项目的目录结构及介绍
angular-best-practices/
├── e2e/
│ ├── src/
│ │ ├── app.e2e-spec.ts
│ │ ├── app.po.ts
│ ├── protractor.conf.js
│ ├── tsconfig.json
├── src/
│ ├── app/
│ │ ├── core/
│ │ ├── shared/
│ │ ├── feature-module/
│ │ ├── app.component.css
│ │ ├── app.component.html
│ │ ├── app.component.spec.ts
│ │ ├── app.component.ts
│ │ ├── app.module.ts
│ ├── assets/
│ ├── environments/
│ │ ├── environment.prod.ts
│ │ ├── environment.ts
│ ├── index.html
│ ├── main.ts
│ ├── styles.css
│ ├── test.ts
├── angular.json
├── package.json
├── tsconfig.json
├── tsconfig.app.json
├── tsconfig.spec.json
├── tslint.json
目录结构介绍
e2e/ : 端到端测试目录,包含测试脚本和配置文件。src/ : 源代码目录,包含应用程序的所有源文件。
app/ : 应用程序的主要代码目录,包含核心模块、共享模块和功能模块。assets/ : 静态资源目录,包含图片、字体等。environments/ : 环境配置目录,包含开发和生产环境的配置文件。index.html : 应用程序的入口HTML文件。main.ts : 应用程序的入口TypeScript文件。styles.css : 全局样式文件。test.ts : 测试配置文件。 angular.json : Angular CLI配置文件。package.json : 项目依赖和脚本配置文件。tsconfig.json : TypeScript编译配置文件。tsconfig.app.json : 应用程序的TypeScript编译配置文件。tsconfig.spec.json : 测试的TypeScript编译配置文件。tslint.json : 代码风格检查配置文件。
2. 项目的启动文件介绍
main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
enableProdMode() : 在生产环境中启用生产模式,禁用Angular的开发模式特性。platformBrowserDynamic() : 使用JIT(Just-In-Time)编译器启动应用程序。bootstrapModule(AppModule) : 引导启动应用程序的主模块AppModule
。
3. 项目的配置文件介绍
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-best-practices": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular-best-practices",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
angular-best-practices This is a guideline of best practices that you can apply to your Angular project. 项目地址:https://gitcode.com/gh_mirrors/ang/angular-best-practices