0

I have create an angular 2 application using the angular-cli like as follow

ng new my-angualr-app

after thay I have build this application on the production mode

ng build --prod

the I got the dist folder.

Finally I move the folder to my apache servers var/www/html directory but the angular 2 application is not working fine.

I could not figureout the issue. Why this is not working. The application working fine on the production mode in local environment, while running the command ng serve --prod

The console error output is here

enter image description here

The Network tab shows 404 status. But the files are resides in the same directory

enter image description here

Community
  • 1
  • 1
nifCody
  • 2,394
  • 3
  • 34
  • 54

2 Answers2

1

Instead of copying the dist folder, copy the contents of the dist folder, and make sure the base href is correct

Fiddles
  • 2,790
  • 1
  • 32
  • 35
  • The problem I found on the network tab is all the file below are hashed and the status of the files are 404 styles.d41d8cd98f00b204e9800998ecf8427e.bundle.css inline.d41d8cd98f00b204e980.bundle.js styles.b2328beb0372c051d06d.bundle.js main.6cc85e1296261ab75a89.bundle.js favicon.ico – nifCody Nov 23 '16 at 07:08
  • The solution is work for me copy the content instead of copy the /dist forlder. why it happens? – nifCody Nov 23 '16 at 08:24
  • It's hard to say without knowing more about your setup. Is your angular app being deployed to the root path? (ie. www.place.com, instead of www.place.com/virtualdir) Is your server doing routing rewrites to root for non-directories? – Fiddles Nov 24 '16 at 00:13
0

I Think You are doing it in wrong way, I am sharing my way of doing-

First of all I use git for repository. So I push my angular2 code which was created by angular-cli. By default, The dist folder is not added in the repository. So I let it as it is.

After that, I clone my angular2 code in the production server in var/www/html and run the ng build --prod there. So, It creates the dist folder for the production server.

I think you can try in this way. It really works for me(in my several projects)

pd farhad
  • 6,352
  • 2
  • 28
  • 47