gpt4 book ai didi

angular - Base-href/deploy-url 参数未按预期工作 : paths aren't changed after building

转载 作者:行者123 更新时间:2023-12-04 02:58:12 26 4
gpt4 key购买 nike

我使用 Angular 6

index.html:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My App</title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>

<script src="./config.js"></script>
</body>
</html>

另外,一个组件的模板包含img标签:

<img src="assets/spinner.gif">

如果我使用 base-href/deploy-url 参数构建它,一切正常(基本 href、所有 css 文件等),除了 config.js 和 assets/spinner.gif 的路径 - angular-cli 保持这些路径没有变化。如何解决?

附言。我尝试使用 "assets/spinner.gif""/assets/spinner.gif""./assets/spinner.gif" - 结果相同。

PPS angular.json 片段:

    {
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"project_name": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/project_name",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/web.config",
"src/config.js",
"src/assets"
],

最佳答案

使用 base-href 参数时,一定要确保所使用的路径以尾随/结尾,并且 HTML 中的路径不以/开头 - 因此您需要以:

<base href="/dir/"/>

<img src="assets/spinner.gif"/>

没有尾随/,将无法正确应用基数。

关于angular - Base-href/deploy-url 参数未按预期工作 : paths aren't changed after building,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51841196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com