问题
In an Angular 7 app i have different assets, images, fonts etc. All are located in src/assets/images or src/assets/fonts, etc
I my files i use them like this: <img src="/assets/images/img.png">
angular.json look like this:
.....
"assets": [
"src/favicon.ico",
"src/assets"
]
.....
When building I use:
ng build --prod --build-optimizer --deploy-url=https://cdn.domain.com
This will replace all the reference to assets resource from this:
<img src="/assets/images/img.png">
to this:
<img src="https://cdn.domain.com/assets/images/img.png">
My question how I can remove the assets/images
path when building so that after building the output will be:
<img src="https://cdn.domain.com/img.png">
回答1:
You could replace
"assets": [
...
"src/assets",
...
]
by
"assets": [
...
{ "glob": "**/*", "input": "src/assets", "output": "/" },
...
]
All the files will be in "/dist/environment/" and not in "/dist/environment/..."
Then in your html files, use directly :
<img src="/img.png">
Have a look here : https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/asset-configuration.md
:-)
来源:https://stackoverflow.com/questions/53962936/angular-7-build-app-replace-assets-url-with-real-url