Skip to content
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

Export shaka as ES6 module #1509

Open
chrisfillmore opened this issue Jul 27, 2018 · 7 comments
Open

Export shaka as ES6 module #1509

chrisfillmore opened this issue Jul 27, 2018 · 7 comments
Labels
flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this priority: P3 Useful but not urgent type: enhancement New feature or request
Milestone

Comments

@chrisfillmore
Copy link
Contributor

chrisfillmore commented Jul 27, 2018

(Edit: updated because at first I was looking at an old version of the template)

I would like to change wrapper.template.js to return shaka from the IIFE so that it can be exported as an ES6 module. It seems the compiler also transpiles the template, which I don't want.

Currently we enable import shaka via a JSPM configuration. I don't see the need for this configuration, and I would like to remove it, if shaka could be exported as an ES6 module. Could the template be changed, or would this be a problem for users who need to support legacy browsers?

To be clear, the change I am proposing is:

wrapper.template.js

// Add export
export default (function() {
  ... template ...
  return exportTo.shaka; // Add return
})();
@TheModMaker
Copy link
Contributor

First, we now compile the wrapper template, so that text will no longer be used directly in the compiled bundle. If I add export default to the current template, Closure will change it a bunch and I don't know if the results are any different than what we have now.

But if I manually change the compiled bundle to add that to the beginning, no browser can read it. Even Chrome gives a syntax error when it tries to read that file; that would require using an ES6 module loader, you can't load that in a <script> tag.

But that wrapper is designed to support different module loaders, maybe we could support what you want to use too. See the comments in the current wrapper.template.js file. How are you loading Shaka Player that it needs this? Does it work without it?

@joeyparrish
Copy link
Member

You can load ES6 modules now in a <script> tag, but only with type="module". The trouble is that adding the "export" keyword makes it incompatible with any other form of module.

@chrisfillmore
Copy link
Contributor Author

We use JSPM for package management and bundling. I'm not intimately familiar with JSPM, but based on my reading, it is configured to read shaka-player.compiled.js as a CommonJS module, and then expose this to use in ES6 module style.

Could the method of export be configured at build time via a flag?

@chrisfillmore
Copy link
Contributor Author

Important detail I forgot to mention: we don't track Shaka as a dependency via npm. I believe there was once a reason for this but I'm hard-pressed to think of it now. Switching it over to npm may obviate the need for es6 module definition. Let me get back to you.

@TheModMaker
Copy link
Contributor

We could have a build-time flag to export as an ES6 module. What we could to is have a second version of wrapper.template.js that would be used for ES6 mode. I'll put this on the backlog, but we would be happy to review a PR for this too.

I am curious though, if JSPM is loading using CommonJS, why doesn't it work? We support loading as a CommonJS module (which doesn't use ES6).

@TheModMaker TheModMaker added type: enhancement New feature or request flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this and removed needs triage labels Jul 30, 2018
@TheModMaker TheModMaker added this to the Backlog milestone Jul 30, 2018
@chrisfillmore
Copy link
Contributor Author

So I realize I never followed up on this. Part of the reason is that our build was undergoing some changes. Now it is quite different. We use Rollup for concatenation and use rollup-plugin-commonjs to bundle Shaka.

We publish our library in ES6 now. Shaka is our only external dependency, so if it was possible to import it as an ES6 module, we wouldn't need to worry about commonjs at all.

We're going through some continued refactoring and migration to TypeScript, so if we think there's some benefit we may file a PR to add ES6 module export support to Shaka.

@joeyparrish joeyparrish modified the milestones: Backlog, Backlog 2 Jan 28, 2020
@TheModMaker TheModMaker added the priority: P3 Useful but not urgent label Sep 29, 2021
@CICCIOSGAMINO
Copy link

What's about the ES6 Module about shaka-player ? I'm try to implement the player in WebComponent.... Insert the global shaka object brokes my element isolation policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this priority: P3 Useful but not urgent type: enhancement New feature or request
5 participants