-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Migrate to Rollup with new ESM target and UMD Worker injection #5299
Conversation
ef48950
to
e8698e1
Compare
This is awesome. Will have a proper look tomorrow |
|
Deploying with
|
Latest commit: |
0097653
|
Status: | ✅ Deploy successful! |
Preview URL: | https://aeee2168.hls-js-e5a.pages.dev |
Branch Preview URL: | https://task-rollup-esm-and-worker.hls-js-e5a.pages.dev |
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.
Hope you don't mind that I pushed a few commits? Look ok?
This looks great though I prefer rollup a lot more than webpack
Will look into getting the es-check bit passing now
package.json
Outdated
"files": [ | ||
"demo/**/*", |
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.
Do we need to include the demo in the package? Not sure if it's useful?
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.
Noticed we're also including the demo build in dist/
in the package. If we don't do this, we probably shouldn't do that either
src/demux/inject-worker.ts
Outdated
import transmuxerWorker from './transmuxer-worker'; | ||
|
||
if (hasUMDWorker() && typeof __IN_WORKER__ !== 'undefined' && __IN_WORKER__) { | ||
transmuxerWorker(self); |
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.
I made some changes in here. Still look ok?
Previously this was assigned to a variable that was unused, and hasUMDWorker
was checking if transmuxerWorker
was defined, and I think it always would be?
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.
I think we could take out hasUMDWorker()
from the check above. It's really only needed in transmuxer-interface for injection.
@@ -1,3 +1,45 @@ | |||
import 'promise-polyfill/src/polyfill'; | |||
const testsContext = require.context('./unit', true); | |||
testsContext.keys().forEach(testsContext); | |||
import './unit/hls'; |
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.
I think we should be able to dynamically generate this file with a plugin. Will probably look into that but this looks good for now
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 alternative is to use something like https://github.com/rollup/plugins/tree/master/packages/multi-entry
The output from the It still is wrapped in a commonjs output tree. I would expect to see Switching to rollup, and the change from webpack definitely resolves a lot of issues, and I don't think this should block that. But I'm not sure this resolves #2910 as is right now. |
I this may be something I broke, checking |
@itsjamie yep I broke it 🤦 Look better now? |
This might still be a problem, and another one I made worse with my commits. Will check |
The ESM build looks like I expect! The implementation of 💯 |
It would help if we had a page that demoed the ESM output. Do we expect developers to use the esm module at runtime or to import and bundle themselves? both? I'd like to get it to where |
I think it's reasonable for this PR to only target bundle users rather than native ESM. |
Did a quick filesize check and seems to have improved slightly: In master
In this PR
|
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.
Testing it out locally, and when loading in the new esm build, it seems to work fine in a pure-client-side app, but in a nextjs app it fails to build with an error about self
not being available as part of self.WebKitDataCue || self.VTTCue || self.TextTrackCue
. I'm still investigating whether it's an hls.js issue or an us issue, but thought I'd post here in the meantime as well.
915594a
to
9eb09ee
Compare
rebased against latest |
It's blatted the commits I added. I'll bring them back on another branch |
Brought them back here #5309 |
8b84d44 should fix that |
We replaced all reference to window with self at some point to prevent issues in the worker context. Is there another alternative that would work in @gkatsev's test case with nextjs? (We've also had issues where self is undefined or overwritten. Not sure if the rollup out formats can do something with global/globalThis/this or something like |
Can confirm that 8b84d44 fixes it. |
Just so I understand, this is when HLS.js is run in nodejs, presumably as part of unit tests? Could we add a build step that tests this? |
Looking for approval to merge and feedback on 39682b6: Add Did some in browser testing of hls.mjs and looks OK to me. If ESM usage, demo, and testing are important to you please contribute the changes you would like to see or need. |
LGTM! Just made a couple more tweaks in #5340 |
Actually the cloudflare pages demo isn't working? |
The worker was not being included in the bundle. I fixed it in #5340 |
...basePlugins, | ||
replace(buildConstants(type)), | ||
...(!shouldBundleWorker(format) | ||
? [alias({ entries: { './transmuxer-worker': '../empty.js' } })] |
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 it worth removing this from the esm build? Is there a way we could leave this to tree-shaking?
Would anyone want to set IN_WORKER and HLS_WORKER_BUNDLE themselves with the esm output?
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.
I think we’d need to export the worker function and then import that function in inject-worker, and then make sure it’s referenced inside an if statement in a way that would cause rollup to not tree shake it away, which is a bit messy
Also not sure what the benefit of it being in there would be, as it would never actually run?
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.
Also not sure what the benefit of it being in there would be, as it would never actually run?
I was thinking someone could use the module to produce a single output that could be used in both contexts as this project does. That's more complicated than it needs to be however.
remove unused `workerInstance` variable refactor rollup config deduped some of the config and configured rollup to bail on any warning Also renamed the command line arg to `configType` as rollup reserved `config*` for custom configs, and won't throw a warning that an unknown property was passed with that downgrade rollup config to cjs and split into 2 files so we can share the config with karma use same rollup config definition for tests and actual build bring the dev script back do not use `const` in `umdBanner` leave test streams file as commonjs but allow it to be imported
which happens in nodejs. The check that makes sure the dist file can be required in node and not throw was failing because of this. Probably only an issue now due to how rollup hoists things
Disable sourcemap in tests Optimize babel settings Rename __HLS_WORKER_BUNDLE__ worker iffe wrapper and remove __HLS_UMD_WORKER__ Don't null config on destroy as it violates public API type defintion
This reverts commit c23df80.
…tup and error logs
7b373ab
to
536dad2
Compare
This PR will...
Migrate from Webpack to Rollup, and improve build output and worker options.
workerPath
(defaults to null)workerPath
to this scriptWhy is this Pull Request needed?
Webpack 5 boilerplate was not getting transpiled to ES5 (#5288). Rollout payload is smaller, and presents an opportunity to address several library output issues such as worker injection (#5107) and es module output (#2910).
Are there any points in the code the reviewer needs to double check?
Resolves issues: