Skip to content

feat(serve): add --hmr flag #3330

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

Merged
merged 6 commits into from
Dec 1, 2016
Merged

Conversation

jschwarty
Copy link
Contributor

Add webpack-dev-server hot module replacement support when the --hmr flag is true.

Add webpack-dev-server hot module replacement support when the --hmr flag is true.
@hansl
Copy link
Contributor

hansl commented Dec 1, 2016

Could you show a warning when this option is used with a link to some HMR documentation? The problem with HMR (and the reason this hasn't been done so far) is that not all angular applications are compatible, and there's no way to know. So we should at least warn the user that their app might break if they don't know what they're doing.

@hansl
Copy link
Contributor

hansl commented Dec 1, 2016

"Some documentation" in this case might be a wiki on our side and/or an external tutorial on HMR + ng2

@jschwarty
Copy link
Contributor Author

Yes, I can add that.

@jschwarty
Copy link
Contributor Author

I added a notice message to the console output when running ng serve --hmr that informs the user that HMR is on for the dev server but requires additional app code to take advantage of it. I included a link to the webpack HMR docs as that describes how the opt-in for HMR works, but I don't know which reliable resource to link to that shows how to do hmr with angular (probably best to have that on the cli wiki).

Although, it may be out of the scope of the cli to be responsible for guiding users into how to do hmr with angular since hmr for webpack dev server is opt-in (just enabling it does not activate your app code to use it). Could be looked at like using the --host or --port flags...cli is just providing the ability to leverage configuring the underlying dev server and what you do with it from there is up to you.

@beeman
Copy link
Contributor

beeman commented Dec 1, 2016

I'm happy to write some docs that help setting up HMR in a project built with the cli, it's just that I did not get it working yet.

I've looked at how angular2-hmr implements this, though their structure is quite different from what the cli generates.

@jschwarty if you could maybe provide a basic cli-generated project with HMR enabled, I'm happy to describe how to build it from a fresh ng init generated project.

@jschwarty
Copy link
Contributor Author

jschwarty commented Dec 1, 2016 via email

@born2net
Copy link

born2net commented Dec 1, 2016

would be sooooo awesome if we can have an example of ng-cli with HMR
TX

Sean

@jschwarty
Copy link
Contributor Author

@beeman
https://github.com/jschwarty/angularcli-hmr-example
Uses @angularclass/hmr package.
Has documentation in the readme.md about HMR stuff.

@hansl
Copy link
Contributor

hansl commented Dec 1, 2016

@jschwarty re

cli is just providing the ability to leverage configuring the underlying dev server and what you do with it from there is up to you.

Agreed, but a lot of people will blame us if they use HMR wrongly in a CLI generated project. I want to avoid issues.

@born2net
Copy link

born2net commented Dec 1, 2016

tx!!!!

@hansl
Copy link
Contributor

hansl commented Dec 1, 2016

LGTM. Thanks.

@hansl hansl merged commit 46efa9e into angular:master Dec 1, 2016
@born2net
Copy link

born2net commented Dec 1, 2016

for me hmr was the killer app ng-cli needed... so now really no need for using webpack directly!!!!

@jschwarty
Copy link
Contributor Author

@hansl re

Agreed, but a lot of people will blame us if they use HMR wrongly in a CLI generated project. I want to avoid issues.

Cool, I agree with avoiding those issues! So where would be the best place to contribute some docs to the cli to help explain HMR and possible usages with a cli project?

@hansl
Copy link
Contributor

hansl commented Dec 1, 2016 via email

@beeman
Copy link
Contributor

beeman commented Dec 1, 2016

@jschwarty thanks for the project. I will write down the steps to get there from a fresh project.

@born2net
Copy link

born2net commented Dec 1, 2016

@beeman tx please update here when done so I can checkout

@beeman
Copy link
Contributor

beeman commented Dec 2, 2016

I created a tutorial that covers setting up HMR with a new app scaffold with angular-cli.

https://medium.com/@beeman/1b0d13b80130

@born2net please let me know if you have any comments. Feel free to post them here, or create an issue on that repo.

@hansl please let me know if you like to see changes in order to get it in the wiki here.

@born2net
Copy link

born2net commented Dec 2, 2016

will do, tx!!!

@jwuliger
Copy link

jwuliger commented Dec 2, 2016

Great stuff!!

@beeman
Copy link
Contributor

beeman commented Dec 2, 2016

@born2net decided to move the tutorial here: https://medium.com/@beeman/1b0d13b80130 , feel free to ping me for any comments.

@born2net
Copy link

born2net commented Dec 2, 2016

great tx!

@born2net
Copy link

born2net commented Dec 2, 2016

maybe add a link to https://github.com/jschwarty/angularcli-hmr-example
as well in blog

@beeman
Copy link
Contributor

beeman commented Dec 2, 2016

@born2net good tip. Though I've linked to the example built using this tutorials so I can keep it updated and reference the commits.

@born2net
Copy link

born2net commented Dec 2, 2016

ok tx!

@born2net
Copy link

born2net commented Dec 4, 2016

In latest angular-cli: 1.0.0-beta.22 getting exceptions....

Here is the PR: #3384

@mattdistefano
Copy link

@jschwarty Do you have an example of this working w/ lazy-loaded routes?

@fabien0102
Copy link

@jschwarty I found this example https://github.com/jschwarty/angularcli-hmr-example but a little doc could be useful 😄

@beeman
Copy link
Contributor

beeman commented Dec 10, 2016

@fabien0102 there's some details in the post I put up on Medium: https://medium.com/@beeman/tutorial-enable-hrm-in-angular-cli-apps-1b0d13b80130 , please let me know if anything is unclear.

@fabien0102
Copy link

@beeman Great! I think you can add this link into angular-cli docs 😉 (It’s always better if all information are consolidate in one place)

@montella1507
Copy link

@beeman are there any additional steps to "keep" HMR working? It worked like a charm in starter solution.

But now it works correctly only for components from 1 module. For another it has to reload entire page with error:

PatrickJS/angular-hmr#42 (comment)

The topic / documentation with common pitfalls in usage of HMR would be very appreciated by the community. Good work anyway!

@rxjs-space
Copy link

@jschwarty , @hansl , Hi, could we have a blueprint for a hmr starter like in the example? So, we can do ng new xyz --hmr and have the hmr setup already.

MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this pull request Feb 9, 2017
@landon-morin
Copy link

@beeman Is there a follow up tutorial on how to get HMR working with lazy loaded modules? I was able to follow your original tutorial and was able to get HMR working perfectly for anything that isn't lazy loaded. Unfortunately my project consists of a large amount of lazy loaded modules.

Is there anything I can do to fix this? Thanks!

@rob-balfre
Copy link

@rxjs-space I've opened a pull request with this new feature today. #5396

@beeman
Copy link
Contributor

beeman commented Mar 13, 2017

@landon-morin I have not tried it with lazy loaded modules yet. This is the issue to track it PatrickJS/angular-hmr#42

@intellix
Copy link
Contributor

intellix commented Mar 13, 2017

I'm guessing since this: #3940, we can create a separate entrypoint so we don't need HMR in production builds

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.