首页
/ Scully 开源项目教程

Scully 开源项目教程

2024-09-08 06:33:16作者:咎岭娴Homer

1. 项目目录结构及介绍

Scully 项目的目录结构如下:

scully/
├── e2e/
├── docs/
├── src/
│   ├── app/
│   ├── assets/
│   ├── environments/
│   ├── favicon.ico
│   ├── index.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles.css
│   └── test.ts
├── .editorconfig
├── .gitignore
├── angular.json
├── package.json
├── README.md
├── tsconfig.json
└── tslint.json

目录结构介绍:

  • e2e/: 端到端测试文件目录。
  • docs/: 项目文档目录。
  • src/: 源代码目录,包含应用程序的主要代码。
    • app/: 应用程序的主要代码文件。
    • assets/: 静态资源文件,如图片、字体等。
    • environments/: 环境配置文件。
    • favicon.ico: 网站图标文件。
    • index.html: 应用程序的主HTML文件。
    • main.ts: 应用程序的入口文件。
    • polyfills.ts: 用于兼容旧版浏览器的填充代码。
    • styles.css: 全局样式文件。
    • test.ts: 测试配置文件。
  • .editorconfig: 编辑器配置文件。
  • .gitignore: Git忽略文件配置。
  • angular.json: Angular项目的配置文件。
  • package.json: 项目的依赖和脚本配置文件。
  • README.md: 项目说明文件。
  • tsconfig.json: TypeScript配置文件。
  • tslint.json: TSLint配置文件。

2. 项目启动文件介绍

main.ts

main.ts 是 Scully 项目的启动文件,负责引导 Angular 应用程序的启动。其主要内容如下:

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(): 在生产环境中启用生产模式。
  • platformBrowserDynamic(): 使用动态浏览器平台引导 Angular 应用程序。
  • bootstrapModule(AppModule): 引导 AppModule 模块,启动应用程序。

3. 项目配置文件介绍

angular.json

angular.json 是 Angular 项目的配置文件,包含了项目的构建、测试、部署等配置。以下是部分配置示例:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "scully": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/scully",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "scully:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "scully:build:production"
            }
          }
        }
      }
    }
  }
}

配置文件功能介绍:

  • build: 定义项目的构建配置,包括输出路径、入口文件、资源文件等。
  • serve: 定义开发服务器的配置,用于本地开发和调试。
  • configurations: 定义不同环境的配置,如生产环境和开发环境。

通过以上配置,可以灵活地控制项目的构建和运行方式。

登录后查看全文
热门项目推荐
相关项目推荐