Angular7:多项目app,防止一个项目的构建编译另一个项目的样式
Angular 7: Multi-projects app, prevent the build of a project to compile the style of another project
这个问题恐怕很难解释。我会尽力解释的。
我的 Angular 应用程序中有 2 个项目:"roldos" 和 "shadra"
当我 运行 为项目构建产品时:ng build --prod --project="roldos"
我收到此错误
奇怪的是,它正在尝试编译 "shadra" 项目中的 app.component.scss。更奇怪的是,它导入的 "variables.scss" 文件来自 Roldos 而不是 Shadra(两者都有一个 variables.scss 文件)
即使我从我的 angular.json 文件中完全删除了 shadra 项目,我仍然会收到此错误,这让我认为构建只是在寻找它可以找到并尝试编译它的每个 scss 文件。 .
这是我的 angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"shadra": {
"root": "projects/shadra/",
"sourceRoot": "projects/shadra/src",
"projectType": "application",
"prefix": "sha",
"schematics": {
"@schematics/angular:component": {
"prefix": "sha",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "sha"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/shadra",
"index": "projects/shadra/src/index.html",
"main": "projects/shadra/src/main.ts",
"polyfills": "projects/shadra/src/polyfills.ts",
"tsConfig": "tsconfig.json",
"assets": [
"projects/shadra/src/favicon.ico",
"projects/shadra/src/assets"
],
"styles": [
"node_modules/font-awesome/scss/font-awesome.scss",
"node_modules/angular2-draggable/css/resizable.min.css",
"projects/shadra/src/style/app.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"projects/shadra/src/style",
"shared/style"
]
},
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "shared/environments/environment.ts",
"with": "shared/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "shadra:build"
},
"configurations": {
"production": {
"browserTarget": "shadra:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "shadra:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.json",
"projects/shadra/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"roldos": {
"root": "projects/roldos/",
"sourceRoot": "projects/roldos/src",
"projectType": "application",
"prefix": "rol",
"schematics": {
"@schematics/angular:component": {
"prefix": "rol",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "rol"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/roldos",
"index": "projects/roldos/src/index.html",
"main": "projects/roldos/src/main.ts",
"polyfills": "projects/roldos/src/polyfills.ts",
"tsConfig": "tsconfig.json",
"assets": [
"projects/roldos/src/favicon.ico",
"projects/roldos/src/assets"
],
"styles": [
"node_modules/font-awesome/scss/font-awesome.scss",
"node_modules/angular2-draggable/css/resizable.min.css",
"projects/roldos/src/styles.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"projects/roldos/src/style",
"shared/style"
]
},
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "shared/environments/environment.ts",
"with": "shared/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "roldos:build"
},
"configurations": {
"production": {
"browserTarget": "roldos:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "roldos:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.json",
"projects/roldos/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "shadra"
}
所以我的问题是:
"How can I configure my angular app so that the build doesn't try to compile SCSS files from other projects"
问题是由 angular.json
中的 tsConfig
属性 引起的
我认为如果我不需要覆盖它,则没有必要在每个项目中都有一个特定的 tsconfig.app.json
,但显然它是。
所以我在我的项目文件夹
中添加了一个 tsconfig.app.json
文件
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
并且我更新了 angular.json
文件,现在可以使用了。
{
"tsConfig": "projects/roldos/tsconfig.app.json"
}
这个问题恐怕很难解释。我会尽力解释的。
我的 Angular 应用程序中有 2 个项目:"roldos" 和 "shadra"
当我 运行 为项目构建产品时:ng build --prod --project="roldos"
我收到此错误
奇怪的是,它正在尝试编译 "shadra" 项目中的 app.component.scss。更奇怪的是,它导入的 "variables.scss" 文件来自 Roldos 而不是 Shadra(两者都有一个 variables.scss 文件)
即使我从我的 angular.json 文件中完全删除了 shadra 项目,我仍然会收到此错误,这让我认为构建只是在寻找它可以找到并尝试编译它的每个 scss 文件。 .
这是我的 angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"shadra": {
"root": "projects/shadra/",
"sourceRoot": "projects/shadra/src",
"projectType": "application",
"prefix": "sha",
"schematics": {
"@schematics/angular:component": {
"prefix": "sha",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "sha"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/shadra",
"index": "projects/shadra/src/index.html",
"main": "projects/shadra/src/main.ts",
"polyfills": "projects/shadra/src/polyfills.ts",
"tsConfig": "tsconfig.json",
"assets": [
"projects/shadra/src/favicon.ico",
"projects/shadra/src/assets"
],
"styles": [
"node_modules/font-awesome/scss/font-awesome.scss",
"node_modules/angular2-draggable/css/resizable.min.css",
"projects/shadra/src/style/app.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"projects/shadra/src/style",
"shared/style"
]
},
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "shared/environments/environment.ts",
"with": "shared/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "shadra:build"
},
"configurations": {
"production": {
"browserTarget": "shadra:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "shadra:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.json",
"projects/shadra/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"roldos": {
"root": "projects/roldos/",
"sourceRoot": "projects/roldos/src",
"projectType": "application",
"prefix": "rol",
"schematics": {
"@schematics/angular:component": {
"prefix": "rol",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "rol"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/roldos",
"index": "projects/roldos/src/index.html",
"main": "projects/roldos/src/main.ts",
"polyfills": "projects/roldos/src/polyfills.ts",
"tsConfig": "tsconfig.json",
"assets": [
"projects/roldos/src/favicon.ico",
"projects/roldos/src/assets"
],
"styles": [
"node_modules/font-awesome/scss/font-awesome.scss",
"node_modules/angular2-draggable/css/resizable.min.css",
"projects/roldos/src/styles.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"projects/roldos/src/style",
"shared/style"
]
},
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "shared/environments/environment.ts",
"with": "shared/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "roldos:build"
},
"configurations": {
"production": {
"browserTarget": "roldos:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "roldos:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.json",
"projects/roldos/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "shadra"
}
所以我的问题是:
"How can I configure my angular app so that the build doesn't try to compile SCSS files from other projects"
问题是由 angular.json
tsConfig
属性 引起的
我认为如果我不需要覆盖它,则没有必要在每个项目中都有一个特定的 tsconfig.app.json
,但显然它是。
所以我在我的项目文件夹
tsconfig.app.json
文件
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
并且我更新了 angular.json
文件,现在可以使用了。
{
"tsConfig": "projects/roldos/tsconfig.app.json"
}