-
-
Notifications
You must be signed in to change notification settings - Fork 68
Fix: Absolute paths being used when expose-loader exposes more than one global for a library #59
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
Conversation
cc @timse Sry for pinging :), but I'm not too familiar with the internals of this loader and don't use it in an active project atm to test and it is related to cache invalidation aswell 😛 would you mind reviewing this PR ? 🙏 |
Sure can do, I am not sure I fully understand the problem. The resolution of non-absolute paths should not be handled by the loader - and I can't reproduce your problem locally @xicreative |
Yeah, here's the situation that we ran into that inspired this PR: Here's a repo to demo the issue: https://github.com/xicreative/demo-webpack-expose-loader Steps:
This behaviour does NOT happen if one of the objects in the loaders: [{
test: require.resolve('jquery'),
use: [
{
loader: 'expose-loader',
options: '$'
},
// {
// loader: 'expose-loader',
// options: 'jQuery'
// }
]
}] This MAY be caused in part by the combination of |
hmm fair enough - i guess there is some weird stuff happening when the hash gets calculated. However for me this seems to be a flaw in webpack itself and should not be handled by every loader. Any opinions @d3viant0ne @michael-ciniawsky ? |
If it is not webpacks responsibility then I would rather argue to allow for multiple globals to be exposing the same module. E.g. by allowing
or
|
Since 'needs repro' is still flagged: My webpack4 setup has suddenly decided to be 'unhappy' with me, choking on use of 'expose-loader' for jqeury. With this in config -- which had, until yesterday, been working great --
I'm now seeing
if I comment out
no more issues. why it 'suddenly' started being an issue, dunno |
@xicreative Thanks! Your solution works! 👍 @evilebottnawi @michael-ciniawsky @d3viant0ne Hey guys when will it be merged? Could you please take care about it. This issue is very important for users who use If you need any help with testing or reproducing, please, just let us know. |
@xicreative can you rebase you PR? |
@evilebottnawi Rebase in progress. Also looking at ways to provide options as @timse suggested, as that seems more efficient. |
Add tests to ensure that given options are assigned to the global/window object.
Ensure the path given to require for multiple exposures of the same object is absolute
As suggested by @timse in PR webpack-contrib#59, expose multiple via an expose property on the loader options object, e.g. options: { expose: ['jQuery', '$'] }
@evilebottnawi This is ready to be re-reviewed. I added some tests that may be a little heavy-handed but I wanted to make the sure the desired globals were actually being exposed on the |
Can we get an update on any progress getting this merged? |
Hey @xicreative have you heard back on this PR? We've been using this fork in production for some time, and it's been working great for us. |
@NathanKleekamp I haven't... it's in the hands of @evilebottnawi & @ooflorent at the moment. |
Hi @xicreative, @evilebottnawi, and @ooflorent. I just wanted to ping the PR again after the New Year in the hopes we can get the changes approved and merged. Thanks! |
Just thought I'd ping @xicreative, @evilebottnawi, and @ooflorent again to see if any progress has been made getting this PR merged or what, if anything, I can do to help get it merged. Thanks! |
Sorry @NathanKleekamp this one's out of my control. |
Would it make more sense to use Would be great to see a bit more movement on this PR as it does break consistent hashing across different machines. See this article: https://medium.com/@the_teacher/webpack-different-assets-hashes-on-different-machines-the-problem-the-solution-ec6383983b99 |
When using expose launcher to expose more than one global for a library, e.g.
the
remainingRequest
for one of the sources is a reference to the already-loaded libaray:/Users/foo/projects/bar/node_modules/expose-loader/index.js?jQuery!/Users/foo/projects/bar/node_modules/jquery/dist/jquery.js
Since the existing logic doesn't change the path of the
expose-loader/index.js
file from absolute to relative, and this value is used in the webpackchunkhash
value, we were experiencing miss-matched hashes for the same file if built from a differently-named directory.The result of this PR would change the
require
in the return from this:to this:
tl;dr