Reputation: 2479
I have a project that runs fine & also when I ran the command ng build--prod
it complies successfully & I get the dist folder in my project. Now I have xammp installed on my machine so I copied that folder & pasted in the htdocs
folder. So now I can access that folder as localhost/dist but the app throws the below errors & app is not running. Can any one tell me whats the problem exactly.
GET http://localhost/styles.34c57ab7888ec1573f9c.css 404 (Not Found)
GET http://localhost/main.d3384476e7e827a9f05c.js 404 (Not Found)
Upvotes: 1
Views: 683
Reputation: 1000
1) ng build --prod
2) index.html should be like that.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App</title>
<base href="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
3) Copy from dist folder and you can put any server and run.
4) To view result call like eg. http://localhost:80/app
Upvotes: 0
Reputation: 186
In Angular 6, you can specify the baseHref and deployUrl in "angular.json" config.
{
...
"projects": {
"project-name": {
...
"architect": {
"build": {
"options": {
"baseHref": "/dist/",
"deployUrl": "/dist",
...
}
}
}
}
}
}
In this way, you don't have to modify your index.html and also don't need to input extra params in command line to build your app.
Upvotes: 2
Reputation: 2405
By default baseUrl
is /
hence it starts looking for resources in the root folder.
You have two possible solutions.
Specify the base URL. you can specify base URL in index.html
manually as
in head
tag
<base href="dist/">
Or you can specify it on the time of building angular-cli has a builtin switch --base-href
E.g:
ng build --prod --base-href /dist/
For more information refer to angular-cli documentation
Upvotes: 3