首页 > 解决方案 > 如何在 `angular.json` 中配置内联样式和 html 模板?

问题描述

看起来所有教程都显示了如何以旧angular.cli.json格式配置它。

"defaults": {
  "styleExt": "css",
  "component": {
    "inlineStyle":true,
    "inlineTemplate":true
  }
}

但不是angular.json格式。这就会产生错误Workspace needs to be loaded before it is used

那么我如何更改现有项目的配置以使用内联模板和 CSS/SCSS 生成组件

谢谢。

标签: angular-cliangular-schematics

解决方案


在研究了angular CLI命令并使用该设置生成一个新项目后,我使用了该解决方案:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "project-name": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "inlineTemplate": true,
          "inlineStyle": true,
          "styleext": "scss"
        }
      }, ....
}

推荐阅读