DEV Community

Edouard Penin
Edouard Penin

Posted on

14

Testing an angular build with base-href locally

We ran into a deployment issues with my team, Angular wasn't able to fetch the translations files.

Being good developers (read lazy 😊) we tried to reproduce (and fix) the issue by running the production build locally rather than deploying again and again.

Well this turned out to be a bit of a hassle 😵.

Thankfully, the amazing angular-http-server package solves all this hassle with a single one liner.

So, let's do this.

First build (obviously)

Note that we specified a base href, this is where most suggested serve methods will fail.

ng build --prod --base-href /pancakesAreTheBest/

Run the production build

npx angular-http-server --path dist/{yourAngularAppName} --baseHref pancakesAreTheBest --open

Let's unpack

  • path simply tells where the build files are
  • baseHref matches the --base-href you used during the build process. (Note, no trailing/starting "/" in the baseHref)
  • open will nicely open the browser for you once ready

More

You can find the docs here, but as a quick overview, angular-http-server also provides a ways to deal with cors, https and custom certificates.

Hope this helps 😇

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
stargator profile image
Stargator

Is pancakesAreTheBest the app name? I'm confused by it's meaning. Or is it just any generic folder name?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay