-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat - Add support for webpack 5 #33
feat - Add support for webpack 5 #33
Conversation
@shilman Ok. Likely webpack 4/5 can be done but it's not going to be very pretty. I'm going to need some nice way to handle conditional imports in TS if we go this way. I'll await more info before hacking around. 😺 |
Yeah if we can solve it cleanly on the storybook end, I can imagine a major breaking change will be more clean |
I gave it some extra thought. A potential way to solve the webpack 4/5 API issue (it has mainly to do with internal APIs and our reliance on them) would be to implement a small adapter in between that's normalizing the few imports I need since it's easy to do handle dynamic imports in CommonJS. That's one way forward though likely typing will be a bit weird. |
For cache detection you can just check Also note, that you can use custom dependency in webpack 4 too. So the way how you modify modules could be exactly the same. Also it's not that hard to make tests against both 4 and 5 versions. See https://github.com/7rulnik/isomorphic-env-webpack-plugin/blob/main/e2e/__tests__/plugin.test.js#L14 |
If we want to handle it on the storybook side it looks like there is a solution (thanks @merceyz for your expert guidance!): {
"dependencies": {
"react-docgen-typescript-plugin-v5": "npm:react-docgen-typescript-plugin@^0.5.0",
"react-docgen-typescript-plugin-v6": "npm:react-docgen-typescript-plugin@^0.6.0"
}
} This aliasing is supported in npm >= |
I've restored support for webpack 4 including caching. Now in case it's running with something else than webpack 5, it's using the old code path. There's also a small testing setup in place to assert the plugin works against both webpack 4 and 5. The remaining question is what to do with webpack 5 and caching. Now it's relying on the cache provided with webpack 5 (not fully tested). I could add webpack 4 style caching on top of that if you think it would be beneficial. More notes below.
Thanks. That's a good tip.
Ok, that's a good point. I've restored the old code path as it became tricky with typings and imports. webpack 5 changed the location of a couple of modules we depend on and typings changed completely as well.
I added a |
@hipstersmoothie can we get another canary pretty please? 🙏 |
It looks like not all modules have it so it could crash here.
It looks like the other type can fail after compiled to JS.
For a reason that's not completely clear webpack emits a path here. Better remove it.
@hipstersmoothie I've released my own canaries at |
Here the latest |
@hipstersmoothie Yes, I've tested it with both webpack 4 and 5 and it seems to be working great! |
@bebraw When you're ready I can hit merge! |
@hipstersmoothie I don't have anything else in mind for this one. Since the change is backwards compatible, it can be a minor release even. |
@hipstersmoothie what's holding this up? |
🚀 PR was released in |
As requested by @shilman, I've added webpack 5 support to the plugin. Here are the highlights of the work:
TODO
. I struggled especially with webpack's typings as they aren't well exposed (mainly docstrings + the exported types are missing some I needed here)I haven't tested the work on anything bigger so I would expect there may still be some issues to uncover. It's also unclear if webpack 5 caching will simply work or if some small change is needed. It's not clear how to test that effectively yet.
TODO:
Closes #30.