Title: Support Webpack HMR with non-root base URLs · Issue #488 · aspnet/JavaScriptServices · GitHub
Open Graph Title: Support Webpack HMR with non-root base URLs · Issue #488 · aspnet/JavaScriptServices
X Title: Support Webpack HMR with non-root base URLs · Issue #488 · aspnet/JavaScriptServices
Description: Since Webpack dev middleware is a dev-time-only (not production) feature, this will only affect people whose development environment is set up to host their site at a non-root URL (e.g., http://localhost:port/somedir). This is a very unu...
Open Graph Description: Since Webpack dev middleware is a dev-time-only (not production) feature, this will only affect people whose development environment is set up to host their site at a non-root URL (e.g., http://loc...
X Description: Since Webpack dev middleware is a dev-time-only (not production) feature, this will only affect people whose development environment is set up to host their site at a non-root URL (e.g., http://loc...
Opengraph URL: https://github.com/aspnet/JavaScriptServices/issues/488
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support Webpack HMR with non-root base URLs","articleBody":"Since Webpack dev middleware is a dev-time-only (not production) feature, this will only affect people whose development environment is set up to host their site at a non-root URL (e.g., http://localhost:port/somedir). This is a very unusual configuration, and in fact is quite hard to set up even on its own as you most likely need some external reverse proxy (e.g., nginx) on your development machine to make that happen. Very few people will do this.\r\n\r\nNow, for people who do that, HMR won't work out-of-the-box right now, because the Webpack configuration doesn't know what directory you're hosting your app inside.\r\n\r\nThe PathBase information doesn't exist until runtime inside the context of a specific HTTP request where `PathBase` has been populated by [UsePathBaseMiddleware](https://github.com/aspnet/HttpAbstractions/blob/87cd79d6fc54bb4abf07c1e380cd7a9498a78612/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseMiddleware.cs). This is tricky for HMR, because the HMR's endpoint (e.g., `/__webpack_hmr`) is compiled into your `.js` bundle at build time.\r\n\r\nThe best solution I have in mind is:\r\n\r\n * Instruct developers that, if they plan to deploy to a non-root URL, then they have to configure `publicPath` values in their Webpack config accordingly. The `publicPath` values must truly reflect the URLs that browsers need to make requests to (this is the case even for regular production deployments; it's not specific to HMR).\r\n * At dev time, having correctly-prefixed `publicPath` values (e.g., `/vdir/dist/`) will automatically configure the client-side code to fetch HMR updates (e.g., blah123123.hot-update.json) from under that URL root\r\n * However, on its own, it would break the HMR proxying, because the current .NET-side proxying code would then start listening for requests under `/vdir/vdir/dist`.\r\n* To fix that latter problem, add a further option on WebpackDevMiddlewareOptions: `BaseUrl`. Amend the proxying code to automatically strip off that prefix from the `publicPath` values that it adds proxy listeners for.\r\n* Also, the .NET-side HMR code can add the configured `BaseUrl` value as a prefix onto the `hotModuleReplacementEndpointUrl` that it passes to the Node code. Then the client will correctly attempt to connect to (e.g.) `/vdir/__webpack_hmr` instead of just `/__webpack_hmr`.\r\n\r\nSo, it's not going to make things automatic for developers, but:\r\n\r\n * It's inevitable that they have to tweak `publicPath` values in Webpack config manually, because that's a compile-time item, and must actually reflect real URLs so that things like images/CSS/etc can actually be loaded from their true complete URLs in production\r\n * It's (almost) inevitable that some specific `BaseUrl` must also be configured, because otherwise there wouldn't necessarily be a single specific one we can use when controlling the HMR endpoint location. The only way to avoid this would be if we delayed WebpackDevMiddleware compilation until requests actually started, and then obtained the `PathBase` from the incoming requests.","author":{"url":"https://github.com/SteveSandersonMS","@type":"Person","name":"SteveSandersonMS"},"datePublished":"2016-12-05T16:45:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/488/JavaScriptServices/issues/488"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:221096cb-71d4-59e6-f3a3-38e3414db46c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CE4:1A6433:3798E91:49963DE:69745DDD |
| html-safe-nonce | e607f5f23b91f25807db5db9b5e9662f88d5a3bca915e654f24bb9232c25fd65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0U0OjFBNjQzMzozNzk4RTkxOjQ5OTYzREU6Njk3NDVEREQiLCJ2aXNpdG9yX2lkIjoiOTE5ODAwOTAxNTQ5NTU4MTE0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1e0dd66645a7bc05997d30925ece5f8bb9d1d91b597c12aa02e3bc3aa0437106 |
| hovercard-subject-tag | issue:193549301 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/aspnet/JavaScriptServices/488/issue_layout |
| twitter:image | https://opengraph.githubassets.com/952d46ddf5954b2f80f10acca236496f8ed394a8a3a8e6ebc3d3156bf517a233/aspnet/JavaScriptServices/issues/488 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/952d46ddf5954b2f80f10acca236496f8ed394a8a3a8e6ebc3d3156bf517a233/aspnet/JavaScriptServices/issues/488 |
| og:image:alt | Since Webpack dev middleware is a dev-time-only (not production) feature, this will only affect people whose development environment is set up to host their site at a non-root URL (e.g., http://loc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SteveSandersonMS |
| hostname | github.com |
| expected-hostname | github.com |
| None | e0b95d743b7672c9ac0e1032d5f117950182dc164a83434a7db86510e8f0b37c |
| turbo-cache-control | no-preview |
| go-import | github.com/aspnet/JavaScriptServices git https://github.com/aspnet/JavaScriptServices.git |
| octolytics-dimension-user_id | 6476660 |
| octolytics-dimension-user_login | aspnet |
| octolytics-dimension-repository_id | 45365298 |
| octolytics-dimension-repository_nwo | aspnet/JavaScriptServices |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45365298 |
| octolytics-dimension-repository_network_root_nwo | aspnet/JavaScriptServices |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fe7e2e8de6e57740bca50402351ea656f7a4bf |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width