iansinnott / react-static-boilerplate

A boilerplate for building static sites with Webpack 2, React and React Router
107 stars 16 forks source link

Npm run build does not compile properly for Routes, CSS & images #22

Closed tonychew1986 closed 6 years ago

iansinnott commented 7 years ago

Could you link me to a repository where I can reproduce?

tonychew1986 commented 6 years ago

So sorry about this... I realised that it is just not loading in production on sub directory. It works on root. Would you know how I could resolve this issue?

iansinnott commented 6 years ago

I'm still not sure exactly what the bug is. Can you describe it more? Or link to a repository where I can reproduce?

tonychew1986 commented 6 years ago
  1. Npm run start ( It works )
  2. Npm run build & deployed to root of web server ( It works )
  3. Deployed to sub directory e.g. xxx.com/staging ( It doesn't work )

Not sure if its something i'm doing wrong or is there some parameters I need to change.

Anyway really appreciate the help. :)

iansinnott commented 6 years ago

Hm, yeah does it work in development mode?

To me this sounds like something to do with React router not being at the root. I bet this is something they support but I'm not sure.

tonychew1986 commented 6 years ago
  1. No problem in development mode
  2. Hm... alright. I don't think its something wrong with your code but more of the configuration side of things. I'm having the same issue with other templates when i try to build and deploy to sub directory. Not too sure whats the right solution.
iansinnott commented 6 years ago

OK, i'm going to close this one out then. But feel free to reopen if you think this is an issue with this project.

Maybe review the React Router docs and see if they cover having your root route at a sub directory as you said.

tonychew1986 commented 6 years ago

Thanks ian.

Anyway I found the solution and I thought I should just share.

This is basically it, by using basename to define your subdirectory: