繁体   English   中英

角示意图。 自定义angular.json文件

[英]Angular Schematics. Customizing the angular.json file

当我使用原理图(ng new --collection = @ foo / schematics myproject)构建站点时,一切正常,除了以下几点:

生成的angular.json文件在styles数组中仅包含一个样式文件,我需要它包含多个自定义样式文件:

在构建新原理图之后的当前angular.json:

"build": {
  "options": {
    "styles: [
      "src/styles.scss"
    ]
  }
}

期望:

"build": {
  "options": {
    "styles: [
      "src/styles.scss",
      "src/custom1.scss",
      "src/custom2.scss"
    ]
  }
}

如何告诉角度示意图例程要包含这些其他样式表?

我不确定这是否是最佳做法,但最近我也不得不弄清楚这是...我所做的...

 function updateAngularJson(options: any): Rule { return (host: Tree, context: SchematicContext) => { updateAngularJsonOptions(host, options); return host; } } function updateAngularJsonOptions(host, options) { var projectDir = (options.directory || options.name) + '/'; var configPath = projectDir + 'angular.json'; var workspace = getWorkspace(host, projectDirectory); if (host.exists(configPath)) { var currentAngularJson = host.read(configPath)!.toString('utf-8'); var json = JSON.parse(currentAngularJson); var optionsJson = json['projects'][options.name]['architect']['build']['options']; optionsJson['assets'].push("src/custom1.scss"); optionsJson['assets'].push("src/custom2.scss"); json['projects'][options.name]['architect']['build']['options'] = optionsJson; host.overwrite(configPath, JSON.stringify(json, null, 2)); } else { throw new SchematicsException('angular.json not found at ' + configPath); } return host; } 

请仔细检查上面的代码-由于某种原因,我无法复制/粘贴我的工作解决方案,因此我为寻求帮助而键入了此代码。希望您能从上面得到启发...对于我...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM