Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume the project is hosted at the root #21

Closed
gaearon opened this issue Jul 18, 2016 · 13 comments
Closed

Don't assume the project is hosted at the root #21

gaearon opened this issue Jul 18, 2016 · 13 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Jul 18, 2016

We currently have an assumption in publicPath in webpack.config.prod.js that the bundle is served from the root, but it may not be (e.g. with GH Pages, it’ll be at you.github.io/projectname/).

I don’t want to add configuration for this but it would be great if we could parse homepage from package.json and use it to determine the publicPath. We can then document it or add a prompt (or a notice) as part of the creation flow.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 18, 2016

Feel free to jump in to help!

@sotojuan
Copy link

I got this, will do a PR soon-ish. Can we just require the package.json in the Webpack config and get the homepage from there? What would be a working default if not set? Just need a bit more info!

@gaearon
Copy link
Contributor Author

gaearon commented Jul 22, 2016

Can we just require the package.json in the Webpack config and get the homepage from there?

Yes, I think so.

What would be a working default if not set?

If not set, assume we want to serve from /. Otherwise extract path from the URL.

@selfup
Copy link

selfup commented Jul 22, 2016

@sotojuan Would be great to set homepage path!

Thanks for taking the initiative

@selfup
Copy link

selfup commented Jul 22, 2016

The hard part with gh-pages is that we would need the new index.html to be at root, and then reference the files in the build dir.

I made a script that deletes everything but src, node-modules, and build. And copies the files in build so that they are at root for gh-pages. Let me know if that could help a bit or if the webpack route is the better way and then just figuring out how to update the index.html for gh-pages

@gaearon
Copy link
Contributor Author

gaearon commented Jul 22, 2016

I’m a bit confused about what you mean. npm run build should produce index.html in build that references local files. The only thing we need to fix is the publicPath setting so it contains paths relative to the actual website.

@selfup
Copy link

selfup commented Jul 22, 2016

gh-pages looks at the root index.html

Does it look inside of build as well?

@selfup
Copy link

selfup commented Jul 22, 2016

Inside of: ./node_modules/react-scripts/config/webpack.config.prod.js

  output: {
    path: buildPath,
    filename: '[name].[chunkhash].js',
    chunkFilename: '[name].[chunkhash].chunk.js',
    // TODO: this wouldn't work for e.g. GH Pages.
    // Good news: we can infer it from package.json :-)
    publicPath: './'
  },

When I changed the public path to "./" everything works!

Running hs for http-server still works as well.

Now how could we avoid the react-router issues you were concerned about?

@gaearon
Copy link
Contributor Author

gaearon commented Jul 22, 2016

We can’t avoid it with ./. It won’t work correctly.
We’ll need to think more about this.

@selfup
Copy link

selfup commented Jul 22, 2016

Ok thanks for continuing the discussion. I'll mess around with adding routes and seeing what works or not.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 22, 2016

You can use my "todos" repo as good testbed. (Make sure to switch to branch with the biggest number.) Then play with opening /active or /completed and refreshing.

@meghprkh
Copy link

Another thing is passing publicPath to dev server doesnot work well with history api fallback. See webpack/webpack-dev-server#518 and webpack/webpack-dev-server#216

@meghprkh
Copy link

If this is done using any kind of config, it must be in such a way IMO that the publicPath should be accessible from the main code.

nicosommi pushed a commit to nicosommi/create-react-app that referenced this issue Mar 17, 2018
* feat(react-scripts/prod): use new uglifyJsPlugin for ES6 support

this closes facebook#21, facebook#158, facebook#248

* feat(react-scripts/prod): execute uglify plugin parallel + enable caching
@lock lock bot locked and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants