Angular 12 CLI 支持使用pug模板语言,需要在安装了pug-loader和pug-plain-loader之后,进行配置。以下是在Angular 12项目中配置pug模板的示例:
npm install pug pug-loader pug-plain-loader --save-dev
"projects": { "my-app": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": {}, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/my-app", "index": "src/index.pug", // 将index.html文件改为index.pug文件 "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] },
app.component.pug
div.container h1 Hello, World!
app.component.ts
import { Component } from '@angular/core'; import { AppComponentPug } from './app.component.pug';
@Component({ selector: 'app-root', template: AppComponentPug }) export class AppComponent { title = 'my-app'; }