开源项目 Cashew 使用教程
1. 项目的目录结构及介绍
cashew/
├── src/
│ ├── app/
│ │ ├── components/
│ │ ├── services/
│ │ ├── models/
│ │ ├── guards/
│ │ ├── interceptors/
│ │ ├── directives/
│ │ ├── pipes/
│ │ ├── modules/
│ │ └── app.component.ts
│ │ └── app.module.ts
│ ├── assets/
│ ├── environments/
│ ├── index.html
│ ├── main.ts
│ ├── styles.css
│ └── test.ts
├── angular.json
├── package.json
├── tsconfig.json
└── README.md
目录结构介绍
src/
:项目源代码目录。app/
:应用程序的主要代码目录。components/
:存放组件文件。services/
:存放服务文件。models/
:存放数据模型文件。guards/
:存放路由守卫文件。interceptors/
:存放拦截器文件。directives/
:存放指令文件。pipes/
:存放管道文件。modules/
:存放模块文件。app.component.ts
:应用程序的根组件。app.module.ts
:应用程序的根模块。
assets/
:存放静态资源文件。environments/
:存放环境配置文件。index.html
:应用程序的入口HTML文件。main.ts
:应用程序的入口文件。styles.css
:全局样式文件。test.ts
:测试配置文件。
angular.json
:Angular项目的配置文件。package.json
:项目的依赖和脚本配置文件。tsconfig.json
:TypeScript配置文件。README.md
:项目说明文档。
2. 项目的启动文件介绍
main.ts
main.ts
是 Angular 应用程序的入口文件,负责引导应用程序的根模块 AppModule
。
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));
index.html
index.html
是应用程序的入口HTML文件,包含应用程序的根组件 <app-root>
。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cashew</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
3. 项目的配置文件介绍
angular.json
angular.json
是 Angular 项目的配置文件,包含项目的构建、开发服务器、测试等配置。
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"cashew": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/cashew",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/poly