简体   繁体   English

Angular.json有脚本和styles两个属性

[英]Angular.json has two properties of script and styles

I was trying adding styles and scripts to my angular.json file but both doesn't seem to work for some reason either bootstrap and others scripts doesn't take effect, later I figure out that there are 2 places to write script and style in angular.json see below我正在尝试将 styles 和脚本添加到我的 angular.json 文件中,但由于某种原因,两者似乎都不起作用,无论是引导程序还是其他脚本,我发现其中的 2 个地方没有写入脚本angular.json 见下文

 { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "angular-firebase": { "projectType": "application", "schematics": { "@schematics/angular:application": { "strict": true } }, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/angular-firebase", "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", "node_modules/bootstrap/dist/css/bootstrap.min.css" ], "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/popper.js/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" ] }, "configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "1mb" }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "4kb" } ], "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "outputHashing": "all"{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "angular-crud": { "projectType": "application", "schematics": { "@schematics/angular:application": { "strict": true } }, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/angular-crud", "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": {

My question is why we have 2 architect.build to insert styles and scripts in angular.json?我的问题是为什么我们有 2architect.build 插入 styles 和 angular.json 中的脚本?

Because some projects may require specific styles for specific environments or only in build or only in service and this way you can specify what you need, in what environment.因为某些项目可能需要特定的 styles 用于特定环境或仅在构建中或仅在服务中,因此您可以指定您需要什么,在什么环境中。

For example, I want to load google analytics in my production build only and not on the server at all so I include it in "scripts" of "production" configuration in "build" and not in the "development" configuration.例如,我只想在我的生产构建中加载谷歌分析,而不是在服务器上,所以我将它包含在"build"中的"production"配置的"scripts"中,而不是在"development"配置中。

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

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