-
Notifications
You must be signed in to change notification settings - Fork 206
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
UMD wrapper doesn't work with webpack #34
Conversation
This partially reverts 31d778c in order to support webpack. Here's a test case you can run at the root of the repository: npm install --global webpack npm run build echo "console.log(require('./'))" > t.js webpack t.js w.js node w.js
@josephfrazier Thanks for tracking this down, I took a brief look at it and I think that we can find a better solution than reverting that part. In particular, browserify doesn't seem to have any issue with the build UMD module, but webpack does an analysis of the bundled modules and it is confused by the UMD wrapper (also, it seems to be a known issue: e.g. webpack/webpack#319). As an experiment, I removed any 'require' from the built UMD module (we don't require anything, and so the require in the UMD wrapper is not really used by anything inside the module) and after this change webpack is able to load the UMD wrapped module without any issue. I think that we can fix this issue with one of the following two strategies:
How that sounds to you? |
Thanks for the quick response. I know we've discussed this before, but I still don't understand why simply using the CommonJS syntax in
This is addressed by the following source code comment: "Note that
Yes, but that's also the case currently, due to the check that was added here, so we'd just be throwing a different type of Error. I went into a bit more detail on this here. Note also that the change I'm proposing here doesn't affect the code output to If you're able to find an alternative solution like the two you mentioned, that works too. I'm just trying to see the downsides of my proposal. EDIT: It is a bit unfortunate that we have to work around webpack specifically, since browserify works (as you mentioned). However, making this change also has the side effect of reducing bundle size, since the UMD boilerplate isn't unnecessarily included into webpack/browserify builds. |
Hi @josephfrazier, I understand your point, but once we agreed on the current approach and we've been finally able to merge the UMD module, I would prefer to fix the issue with webpack as soon as possible, and a solution which is consistent with the approach which we already agreed on is probably the fastest option. In #35 I tried the approach that I described in the previous comment and it seems to work great for both browserify and webpack and it also a pretty small change (fully accomplished by only changing the umd build step). Also, the above PR contains a different testing strategy which should fully ensure that the "module bundlers" that we are interested in are going to work correctly and don't regress. Let me know how #35 looks to you and that it also works for you as expected. |
Hi @rpl, thanks for the quick turnaround with #35. I just tried it and confirmed that the I wish I had tested webpack back in #17, then I would have pushed harder for the CommonJS approach, but #35 looks like it solves the problem too (with the small caveat that you still can't Feel free to close this once #35 is merged. Thanks again! |
@josephfrazier Thanks for the confirmation, I've merged #35 and released it on npm as 0.1.1 (and also added some automation for the npm publishing process, which will make the next releases easier). Also, thanks again for contributing the initial changes for the UMD module wrapping and being able to finally release it on npm, you have been absolutely awesome. PS: I agree that it would be nice if we can provide a simpler way to be able to test pre-releases versions, and we can definitely rethink it in the future (e.g. when we put together a "workflow", and some automation, related to the generation of updates on the api-metadata.json, these metadata are going to need some updates from time to time, to keep them synchronized with the updates on the API schema in mozilla-central). |
@rpl Thanks for quickly merging #35 and releasing! I should be able to use webextension-polyfill in my projects now. It's great to hear that future releases have been automated too, as that should make it much easier to distribute updates. Thanks again for all the work you and the rest of the team have done on this, it's a big help with cross-browser extension development. Regarding pre-release testing, if you were to merge this PR, it should be as simple as |
On the current master branch (96cfb9c), the following test illustrates the issue:
This patch partially reverts 31d778c in order to support webpack.
On my machine, here's the test case output before this patch:
And here's the output after:
Note that this second error is expected, since Node doesn't provide the
chrome
global. The code inw.js
can be pasted into a browser, where it works correctly.Related issues: