react-webpack-generators / generator-react-webpack

Yeoman generator for ReactJS and Webpack
http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
MIT License
2.88k stars 355 forks source link

Can't Find app.js When Deployed #236

Closed JimLynchCodes closed 8 years ago

JimLynchCodes commented 8 years ago

I make a dist build by running this:

npm run dist

I then push that to master. Then I push it to my gh-pages branch on github like this:

git subtree push --prefix dist/ origin gh-pages

I can see all the files in the gh-pages root as they should be: https://github.com/JimTheMan/React-Webpack-Project/tree/gh-pages screen shot 2016-06-12 at 11 59 33 am

But then when I navigate to the site it just shows the "can't find app.js" error. :( http://jimtheman.github.io/React-Webpack-Project/ screen shot 2016-06-12 at 12 02 22 pm

JimLynchCodes commented 8 years ago

I seemed to have been able to fix the build script by going into cfg/base.js and changed line 18:

path: path.join(__dirname, '/../dist/assets'),

to this (extra slash on the end of assets):

path: path.join(__dirname, '/../dist/assets/'),

Only then does it work. But this is a strange thing for it to happen to only me. Surely I am not the only one deploying my files. So then why is this happening? Can we add the / to master, or am I doing something wrong that it doesn't work out of the box?

weblogixx commented 8 years ago

Hi @JimTheMan,

seems to be related to https://github.com/newtriks/generator-react-webpack/issues/233. I will have a look at this and eventually fix it in one of the next versions.

JimLynchCodes commented 8 years ago

Hmm. It seems like I am getting the error again even with the extra slash.

JimLynchCodes commented 8 years ago

Had to also take out the / from the path in index.html

Changed

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

to

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

weblogixx commented 8 years ago

Hi Jim,

just received your original comment. There are some things wrong with the way you think creating dist versions work. You should really never use a webpack dev server for serving your project live.

All that matters is the dist version of app.js. Most people do not even use the included index.html, but upload their projects for usage with apache, lighthttp or cdns. So it is not as big of a bummer that you might think it is.

Just setting the path so it works for your setup is a easy step for current usage. Think about it: There are people using it on their primary domain, subdomain, cdn or a folder or even other ports (non default http). There is no setup that fits everyone. Hope this info helps.

\ Edit: Updated formatting and language. Writing on iphone sucks... **

WillTheSun commented 8 years ago

Hey Jim,

Thanks a lot for posting this. I had the same problem when trying to deploy to GitHub pages and your edits worked perfectly.