-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix builder-webpack 5 usage in ESM environment #18620
Fix builder-webpack 5 usage in ESM environment #18620
Conversation
In ESM environments, require isn't available. Furthermore, it is required to specify file extensions while importing files. This MR will fix the usage of builder-webpack 5 in ESM environments (type: module is defined in package.json).
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 0186b8f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
@@ -32,7 +34,7 @@ window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore | |||
|
|||
preview.initialize({ importFn, getProjectAnnotations }); | |||
|
|||
if (module.hot) { | |||
if (import.meta.webpackHot) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a backwards compatible change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The folder structure indicates, that this template is exclusively used for the webpack 5 builder. As I have understood the docs, it is totally valid to use this syntax also for CommonJS environments (https://webpack.js.org/api/hot-module-replacement/). So if your question is about backwards-compatibility regarding CommonJS environments, then yes. It should work. Especially, because it is already used in the next line.
@valentinpalkovic Let's discuss this, I think this type of experimental work should be done based on |
Besides snapshots needed to be updated, this is good to merge. Fantastic work @valentinpalkovic |
This brings up an interesting question. A bunch of addons all have something like this: if (module && module.hot && module.hot.decline) {
module.hot.decline();
} Should this be updated across the board to match the webpack5 and vite syntaxes? (they're different, unfortunately) And maybe the addon-generator too? |
It would help to upgrade the webpack version to ~5.74.0 - it adds a new feature
https://github.com/webpack/webpack/releases/tag/v5.74.0 |
@valentinpalkovic I updated the PR for you, how do you feel about this PR? close to getting merged? And what about |
Regarding your comment @IanVS
I don't think they should. This code is to help in addon development (if it even helps at all these days) and certainly shouldn't be shipped to users. I deleted that code from a bunch of monorepo addons. |
Is this still relevant @valentinpalkovic ? |
@yannbf Yes, as soon as I have some time I will try to get this in. |
@valentinpalkovic I think this PR isn't going to be very helpful anymore, considering the merge conflicts. |
Issue:
What I did
In ESM environments, require isn't available. Furthermore, it is required to specify
file extensions while importing files.
This MR will fix the usage of builder-webpack 5 in ESM environments
(type: module is defined in package.json).
How to test
If your answer is yes to any of these, please make sure to include it in your PR.