PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
505 stars 46 forks source link

Specify publicPath for the webpack dev-server #61

Closed dzolnjan closed 6 years ago

dzolnjan commented 6 years ago

My angular app (index.html) is hosted in asp.net mvc at localhost:51960 and it loads the scripts from standard angular-cli node server that is started with 'ng serve --hmr -e=hmr'.

...
<script type="text/javascript" src="http://localhost:4200/inline.bundle.js"></script>
<script type="text/javascript" src="http://localhost:4200/polyfills.bundle.js"></script>
<script type="text/javascript" src="http://localhost:4200/styles.bundle.js"></script>
<script type="text/javascript" src="http://localhost:4200/vendor.bundle.js"></script>
<script type="text/javascript" src="http://localhost:4200/main.bundle.js"></script>
...

Everything works except the actual hot update which fails to update the scripts. Here is what I see in console when open localhost:51960 and then make a simple source code change:

[HMR] Waiting for update signal from WDS... Angular is running in the development mode. Call enableProdMode() to enable the production mode. [WDS] Hot Module Replacement enabled. [WDS] App updated. Recompiling... [WDS] App hot update... [HMR] Checking for updates on the server... [HMR] Update failed: SyntaxError: Unexpected token < in JSON at position 0 at Object.parse () at XMLHttpRequest.request.onreadystatechange (http://localhost:4200/inline.bundle.js:77:34) at XMLHttpRequest.wrapFn [as zonesymbolonreadystatechange] (http://localhost:4200/polyfills.bundle.js:3484:39) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.bundle.js:2839:31) at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.bundle.js:2606:47) at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.bundle.js:2913:34) at invokeTask (http://localhost:4200/polyfills.bundle.js:3779:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.bundle.js:3797:17)

From my previuos experience with hot module replacement for webpack I remember getting similar error if publicPath was not set for webpack.dev.config, so I'm wondering if there is a way specify this for hrm?

dzolnjan commented 6 years ago

I've just discovered that publicPath can set trough deployUrl like this:

ng serve --hmr -e=hmr --deployUrl http://localhost:4200/