7ball
7ball

Reputation: 2315

Angular CLI build prod javascript/css links don't work

I'm using the Angular CLI to compile my Angular app down to JS and CSS files. I'm using ng build --environment prod to compile.

When looking at the index.html file in the dist folder, I see that the JS and CSS files are linked properly like so:

<script type="text/javascript" src="script.js"></script>

But then when I open the index.html file, Safari complains that these files aren't found. But when I edited the HTML file like so:

<script type="text/javascript" src="file:///Users/me/proj/dist/script.js"></script>

Everything works... How can I fix this? Here's how the dist folder looks like, roughly.

dist
  |--------- index.html
  |--------- styles.css
  |--------- script.js

Upvotes: 0

Views: 547

Answers (2)

Raymond Sicard
Raymond Sicard

Reputation: 122

I solved that problem like this.

ng build --prod --base-href /dist

Upvotes: 0

DeborahK
DeborahK

Reputation: 60548

The dist folder is meant to be deployed to a production server ... not run directly from your system.

As part of the ng build --prod you can specify the base URL to use for your production server. That defines where it will find the files.

ng build --prod --base-href myProductionServerFolder

Upvotes: 2

Related Questions