Can I add a path in dist/index.html references to polyfills.js, main.js, and styles.css in...

Discussão em 'Angular' iniciado por Jeff H., Março 16, 2025.

  1. Jeff H.

    Jeff H. Guest

    I'm trying to load a simple Angular app to GitHub pages.

    When I build, the built index.html file references polyfills.js, main.js, and styles.css. When I go to the home page in GitHub, I get a 404 error when trying to load those 3 files. The issue seems to be that it's searching for those files at my main github.io address (https://jeffhogan-dev.github.io/main-DP3T6CHZ.js), but it should be searching for it in my project folder (https://jeffhogan-dev.github.io/home/main-DP3T6CHZ.js). When I manually change those links in index.html to add the /home path, it works fine.

    Is there a way to make sure that /home gets added on ng build so that I don't have to manually update? Or is there something I can do in Github Pages to make sure those files are findable at the base url?

    Here is my angular.json

    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
    "home": {
    "projectType": "application",
    "schematics": {},
    "root": "",
    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
    "outputPath": {
    "base": "dist",
    "browser": ""
    },
    "index": "src/index.html",
    "browser": "src/main.ts",
    "polyfills": [
    "zone.js"
    ],
    "tsConfig": "tsconfig.app.json",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": [
    "@angular/material/prebuilt-themes/magenta-violet.css",
    "src/styles.css"
    ],
    "scripts": []
    },
    "configurations": {
    "production": {
    "budgets": [
    {
    "type": "initial",
    "maximumWarning": "500kB",
    "maximumError": "1MB"
    },
    {
    "type": "anyComponentStyle",
    "maximumWarning": "4kB",
    "maximumError": "8kB"
    }
    ],
    "outputHashing": "all"
    },
    "development": {
    "optimization": false,
    "extractLicenses": false,
    "sourceMap": true
    }
    },
    "defaultConfiguration": "production"
    },
    "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "configurations": {
    "production": {
    "buildTarget": "home:build:production"
    },
    "development": {
    "buildTarget": "home:build:development"
    }
    },
    "defaultConfiguration": "development"
    },
    "extract-i18n": {
    "builder": "@angular-devkit/build-angular:extract-i18n"
    },
    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "polyfills": [
    "zone.js",
    "zone.js/testing"
    ],
    "tsConfig": "tsconfig.spec.json",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": [
    "@angular/material/prebuilt-themes/magenta-violet.css",
    "src/styles.css"
    ],
    "scripts": []
    }
    }
    }
    }
    },
    "cli": {
    "analytics": "bbfd567c-b1b8-47d4-856a-eb169d2df5c7"
    }
    }

    Continue reading...

Compartilhe esta Página