-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Rollup: Specify AMD id #8843
base: main
Are you sure you want to change the base?
Rollup: Specify AMD id #8843
Conversation
💖 Thanks for opening this pull request! 💖 Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
Can this change break folks that are currently using AMD? I think that would be my only concern with a change like this. |
@gkatsev I don't believe this is a breaking change at all. This is how video.js was until ~6.2.* as well. The Rollup code just uses that new |
Sure, but if someone has amd set up and working with 8.17.3, and we release this change, would they need to change their configuration for it to work again or would it not matter and just would mean less configuration for folks going forward again? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8843 +/- ##
==========================================
+ Coverage 83.18% 83.79% +0.60%
==========================================
Files 120 120
Lines 8047 8047
Branches 1931 1931
==========================================
+ Hits 6694 6743 +49
+ Misses 1353 1304 -49 ☔ View full report in Codecov by Sentry. |
I wasn't sure about this until I built a bunch of test cases! Here's what I've found: Using
Using
So unfortunately it looks like by forcing the module id to <html>
<head>
<link href="lib/video-js.css" rel="stylesheet">
<script data-main="main" src="lib/require.js"></script>
<!-- video.js is at lib/videojs.js -->
</head>
<body>
<script>
require(['lib/videojs'], function(videojs) {
// videojs will be undefined if built with the AMD id of `videojs`
</script>
</body>
</html> In these cases, the file The cases where it continues to work are where the user had already specified the module as <html>
<head>
<link href="lib/video-js.css" rel="stylesheet">
<script data-main="main" src="lib/require.js"></script>
<!-- video.js is at lib/videojs.js -->
</head>
<body>
<script>
requirejs.config({
paths: {
'videojs': 'lib/videojs'
},
});
require(['videojs'], function(videojs) {
// videojs is OK here
</script>
</body>
</html> So I'm not sure where that leaves this PR. This would potentially be a breaking change for some. It would be nice to fix this though. I came across this issue when my ad provider, who is using video.js, started to include it in their bundle. On my site that uses Almond (which requires a name for all modules), video.js wouldn't load. |
we could provide another build that includes it, but the main build would need to wait for a breaking change. |
Description
Today, video.js exports itself as an AMD module (if the site supports AMD) via the UMD header:
The second clause which runs if AMD/RequireJS is active, is a
define(factory)
function call. This is an "anonymous" definition of the module. Being anonymous will break on sites using the lightweight RequireJS shim called almond, which expect all modules to be named.This can be challenging if video.js is being pulled into the site via a third-party, i.e. as part of ads.
Prior to using Browserify/Rollup, video.js had implemented a change to ensure
define('videojs', factory)
was used:#1844
However, after the switch to Browserify, that small change was lost:
#3826
This error is seen by others, i.e. #1843 (comment)
Specific Changes proposed
This PR simply ensures video.js is named for AMD via the
rollup.config.js
.The UMD definition changes to this:
Requirements Checklist
npm run docs:api
to error