You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建过程中如何为index.html路径添加/static/前缀适配Flask

给Angular构建资源路径添加/static/前缀适配Flask

需求说明

需要给index.html中所有资源路径添加/static/前缀,因为Flask会在/root_folder/static目录下查找静态文件。目前已将Angular构建产物放入static文件夹,但因路径未加前缀,导致资源无法正常加载。

当前Flask目录结构

web_ui
    src
       -static
       -web_app.py
    logs
    config

现有index.html资源路径示例

<script src="assets/js/apexcharts.min.js"></script>
<script src="assets/js/bootstrap.bundle.min.js"></script>

期望修改后的路径

<script src="/static/assets/js/apexcharts.min.js"></script>
<script src="/static/assets/js/bootstrap.bundle.min.js"></script>

已修改的Angular配置

已在angular.json中调整了构建输出目录:

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../web_ui/src/static/",  // 此处已修改
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/custom-theme.scss",
              "src/styles.css"
            ],
            "scripts": [
              "src/assets/js/main.js",
              "node_modules/apexcharts/dist/apexcharts.min.js"
            ]

疑问

是否可以通过修改angular.json实现自动给资源路径添加/static/前缀?目前未找到具体操作方法,难道必须手动修改index.html中的路径?


内容的提问来源于stack exchange,提问作者Sam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 05:07:22