angular - 在 ng serve 构建 Angular 库
问题描述
我正在为我的角度库开发而苦苦挣扎。首先,我正在构建一个 Angular 8 库(当前 cli 版本 9),并且我希望在为使用该库的演示应用程序提供服务时实时看到我的库代码更改。
当前行为:当我对库源代码进行更改时,角度演示应用程序会重新加载,但我没有看到任何更改生效。此行为主要应用于 css 更改,而不是每次都应用于 .ts 文件。
预期行为:能够看到我对库源代码所做的每一项更改。
当前的 angular.json 文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"bDataTableDemo": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/bDataTableDemo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "bDataTableDemo:build"
},
"configurations": {
"production": {
"browserTarget": "bDataTableDemo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "bDataTableDemo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "bDataTableDemo:serve"
},
"configurations": {
"production": {
"devServerTarget": "bDataTableDemo:serve:production"
}
}
}
}
},
"ng-bootstrap-table": {
"projectType": "library",
"root": "projects/ng-bootstrap-table",
"sourceRoot": "projects/ng-bootstrap-table/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ng-bootstrap-table/tsconfig.lib.json",
"project": "projects/ng-bootstrap-table/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ng-bootstrap-table/src/test.ts",
"tsConfig": "projects/ng-bootstrap-table/tsconfig.spec.json",
"karmaConfig": "projects/ng-bootstrap-table/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/ng-bootstrap-table/tsconfig.lib.json",
"projects/ng-bootstrap-table/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "bDataTableDemo"
}
还有我的 tsconfig.json 文件
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"ng-bootstrap-table": [
"dist/ng-bootstrap-table"
],
"ng-bootstrap-table/*": [
"dist/ng-bootstrap-table/*"
]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
为了获得预期的行为,我应该改变什么?
PS我是角度库的新手,所以我还找不到解决方案。
先感谢您!!
解决方案
您应该编辑 tsconfig 中的路径以指向您的库的 index.ts 而不是 dist/ - 这是生成的构建工件ng build my-library
:
"my-library" : [ "libs/my-library/index.ts" ]
推荐阅读
- c++ - 通过 std::thread 以 std::function 作为参数调用可调用对象
- wordpress - 如何让所有评论类型显示在 WordPress 中?
- python - TensorFlow matmul如何处理channel=None
- ajax - Codeigniter Ajax 记录已保存但不显示 luvr
- c - 如何使scanf不忽略C中的空格和\ n
- javascript - 这段代码有什么问题?我正在尝试在 Angular 中移动 TS 中的 JS 代码
- python - MinMax 缩放数组,具有整个数组的最大值和最小值
- schema.org - 自定义帖子档案和自定义分类档案的 Schema.org 标记?
- javascript - 将 JSONified 对象传递到 Django 中的后端?
- asp.net - 使用 linq 查找出现在两个列表中的项目