在我的项目构建配置中,我有以下资产声明:
"assets": [
"src/favicon.ico",
"src/assets",
"src/assets/fonts",
"src/images",
"src/web.config"
],
然后在我的部署配置中:
"deploy": {
"assets": [
{"glob": "config.json", "input": "src/environments/", "output": "/"}],
使用"部署"配置进行构建时,不再部署上面声明的资产。仅部署 config.json 文件。
作为解决方法,我必须将这些资产添加到"部署"中的资产数组中。这是正确的方法吗? 或者有没有办法避免覆盖资产构建声明?
我不知道你为什么要配置特定的部署,它已经在angular.json
中配置了,你可以在这个文件中添加一个新配置,如提供的示例运行它 ng build --c=build
或运行第二个确认使用 ng build --c=staging
c 代表配置
顺便说一下,你应该得到包含资产文件的dist文件夹
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/AngularProject",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config",
"src/WEB-INF"
],
"styles": [
"src/styles.scss",
"src/assets/css/fontawesome-all.min.css",
"src/assets/css/themify-icons.css"
],
"stylePreprocessorOptions": {
"includePaths": [
]
},
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/popper.js/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.js",
"./node_modules/jspdf/dist/jspdf.min.js",
"./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.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": "4mb",
"maximumError": "5mb"
}
]
},
"staging": { // a new configuration
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "4mb",
"maximumError": "5mb"
}
]
}
}
},
要部署,使用所需的配置运行ng build
就足够
不确定我是否得到了你的问题
我用architect > build > options > assets >
中的以下条目解决了这个问题:
{
"glob": "**/*",
"input": "<src_base_path>/assets",
"output": "./assets/"
}
src_base_path
可以是:
-
src
:如果要获取所选项目的资源,如本问题所示。 -
projects/<my project>/src
:当您处于多项目配置中并且想要选择任何项目的src
文件夹时。 -
dist/<my project>/src
:与以前相同,但不是获取源,而是获得其处理版本。