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

Tweak config to support HMR #107

Merged
merged 1 commit into from
May 10, 2021
Merged

Tweak config to support HMR #107

merged 1 commit into from
May 10, 2021

Conversation

artonge
Copy link
Contributor

@artonge artonge commented Apr 28, 2021

Tweak the Webpack config to support hot module reloading.

webpack.js Outdated Show resolved Hide resolved
@artonge artonge force-pushed the feature/support_hmr branch from 94fc140 to da4a990 Compare April 28, 2021 15:10
package.json Outdated Show resolved Hide resolved
@artonge
Copy link
Contributor Author

artonge commented Apr 29, 2021

This should be ready to test.

Don't forget to download and enable to HMREnabler app for the server.
You will also have to add this new comand in your package.json:

"serve": "NODE_ENV=development webpack serve --progress --config webpack.js",

@artonge artonge requested a review from juliusknorr April 29, 2021 10:09
@artonge artonge force-pushed the feature/support_hmr branch 3 times, most recently from d5308a7 to 104edd5 Compare May 3, 2021 12:56
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
webpack.js Show resolved Hide resolved
@artonge artonge force-pushed the feature/support_hmr branch 2 times, most recently from 5f444fb to 4572f04 Compare May 3, 2021 16:05
@skjnldsv
Copy link
Contributor

skjnldsv commented May 3, 2021

This is still missing the webpack-dev-server deps, no?

Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be fetching https for me, because my dev instance have a certificate. But the webpack serve only listens to http 🤔

Setting up https: false in the DevServer does not works
https://webpack.js.org/configuration/dev-server/#devserverhttps

@artonge
Copy link
Contributor Author

artonge commented May 3, 2021

Yes,I wasn't sure it was necessary to add it as Webpack install it dynamically on the first webpack serve call and adding it in this package.json won't prevent the need to install it manually.

@artonge
Copy link
Contributor Author

artonge commented May 3, 2021

It seems to be fetching https for me, because my dev instance have a certificate. But the webpack serve only listens to http thinking

Setting up https: false in the DevServer does not works
https://webpack.js.org/configuration/dev-server/#devserverhttps

It might be due to the __webpack_public_path__ override. The generateFilePath function will generate an URL with https.

@skjnldsv
Copy link
Contributor

skjnldsv commented May 3, 2021

Yes,I wasn't sure it was necessary to add it as Webpack install it dynamically on the first webpack serve call and adding it in this package.json won't prevent the need to install it manually.

Since this is a required dep for this lib to work with 100% of its features, we need it as dep and peer dep :)

@artonge artonge force-pushed the feature/support_hmr branch 2 times, most recently from 8b1d815 to e5a07ef Compare May 4, 2021 08:46
@skjnldsv
Copy link
Contributor

skjnldsv commented May 4, 2021

I think it's because my dev setup have a domain, the HMR_enabler doesn't fix the CSP for same-domain request, no?

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:3000/sockjs-node/info?t=1620129348916. (Reason: CORS request did not succeed).

@artonge
Copy link
Contributor Author

artonge commented May 4, 2021

I think it's because my dev setup have a domain, the HMR_enabler doesn't fix the CSP for same-domain request, no?

The problem here is that the Webpack devServer block requests coming from other web pages. This prevent say pirate.com to access the webpack devServer and do bad things.

The solution is to:

  • either set devServer.disableHostCheck to true, which is insecure.
  • or set devServer.allowedHosts to ['domain1', 'domain2', '...'], and try to list all domains used by the developers, which will probably always be incomplete, but maybe we can agree on a set of domains. And we can't do stuff like '*.localhost'.

We could also use a shell environment variable by setting devServer.allowedHosts to [process.env.TEST_DOMAIN] so everyone can do TEST_DOMAIN='nextcloud.test' make serve-js, but maybe that bring to much complexity.

@skjnldsv
Copy link
Contributor

skjnldsv commented May 4, 2021

  • either set devServer.disableHostCheck to true, which is insecure.

Tried this, did not work :/

@artonge
Copy link
Contributor Author

artonge commented May 4, 2021

  • either set devServer.disableHostCheck to true, which is insecure.

Tried this, did not work :/

So, I was able to reproduce your error. It was due to Webpack using https to communicate but as it wasn't listening with https enabled, the requests failed. I pushed a solution to force Webpack to use http. This is the line that say host: 127.0.0.1. For whatever reason the source code has a condition that prevent using the source page's protocol when host is set to 127.0.0.1.

The other problem I reported still stand as you will notice. The current solution is to set an environment variable when running the dev server, but I don't think that is the best.

webpack.js Outdated Show resolved Hide resolved
Copy link
Contributor

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment regarding the environment variable, otherwise this works fine for me in deck with a limitation:

There seems to be an issue with multiple entrypoints that might be loaded from the same app that runs in hot reload mode which then causes the update to be not properly detected, but I'd consider that not as a blocker for now.

Really nice so far 👍

@artonge artonge force-pushed the feature/support_hmr branch from 1a3740a to 11a82da Compare May 5, 2021 17:21
@juliusknorr juliusknorr requested a review from skjnldsv May 10, 2021 08:34
Signed-off-by: Louis Chemineau <louis@chmn.me>
@artonge artonge force-pushed the feature/support_hmr branch from 11a82da to e90ff5e Compare May 10, 2021 09:46
@skjnldsv skjnldsv merged commit 39eb586 into master May 10, 2021
@skjnldsv skjnldsv deleted the feature/support_hmr branch May 10, 2021 13:38
@skjnldsv skjnldsv added the enhancement New feature or request label May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants