angulardeploymentbuildlite-server

Deploying Angular app to server with changed baseHref missing files


This question is related to my previous post and discussion I had in the comments.

Angular base href not showing up in URL

TLDR is that my application runs normal when I test it localy e.g. correctly routes between localhost:4200/page1 and /page2 but it doesn't when I deploy it to a production server with url similar to this production.com/myapp/page1 and /page2.

I am trying to build the Angular app generated with ngX-Rocket with the following command.

ng build --watch --baseHref=/myapp/

The goal is to change the base path on production server. So to test this I used lite-server

lite-server --baseDir="dist"

But I get the following error:

Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync config **
{
  injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  watchOptions: { ignored: 'node_modules' },
  server: { baseDir: 'dist', middleware: [ [Function], [Function] ] }
}
[Browsersync] Access URLs:
 ----------------------------------
       Local: http://localhost:3000
    External: http://10.0.75.1:3000
 ----------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 ----------------------------------
[Browsersync] Serving files from: dist
[Browsersync] Watching files...
19.08.28 13:30:34 200 GET /index.html
19.08.28 13:30:34 404 GET /myapp/runtime.js
19.08.28 13:30:34 404 GET /myapp/styles.js
19.08.28 13:30:34 404 GET /myapp/polyfills.js
19.08.28 13:30:34 404 GET /myapp/vendor.js
19.08.28 13:30:34 404 GET /myapp/main.js
19.08.28 13:30:35 404 GET /myapp/styles.js
19.08.28 13:30:35 404 GET /myapp/vendor.js
19.08.28 13:30:35 404 GET /myapp/main.js
19.08.28 13:30:35 404 GET /myapp/favicon.ico

I can't identify where the problem lies. Is it with my build process? When inspect my dist folder all those files are in root directory where index.html is instead of /myapp/. So any Help would be greatly appreciated.


Solution

  • In angular.json file you can specify the folder. and build ng build --baseHref ./

    ...
    "options": {
                "outputPath": "dist/browser",
                ...
    }
    ...