mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
1d27c295ee
This updates our wrapper in several ways:
- Adds comments and whitespace and meaningful variable names
- Makes the CommonJS loader compatible with Electron, fixing #1463
- Adds a "global" parameter to the inner scope, fixing #1455
- Strips whitespace and comments from the wrapper during the build
The wrapper is much more readable and debuggable, which should help
maintain support for these various module loaders in the future.
Tested and working with the new wrapper:
- CommonJS (NodeJS, etc.)
- AMD (requirejs)
- Electron (loads into global scope without loader, no longer
conflicts with CommonJS)
- ES modules (partially supported, loads into global scope)
Since the wrapper is now fixed in a way that avoids #1455 and
google/closure-compiler#2957, this also reverts
"Patch Closure Compiler to fix polyfill+wrapper",
commit 962ec0a22d.
Closes #1463
Change-Id: I5d3ac056cb8db04dc714afee0cb069f2a45a456d
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
(function() {
|
|
// This is "window" in browsers and "global" in nodejs.
|
|
// See https://github.com/google/shaka-player/issues/1445
|
|
var innerGlobal = typeof window != 'undefined' ? window : global;
|
|
|
|
// This is where our library exports things to. It is "this" in the wrapped
|
|
// code. With this, we can decide later what module loader we are in, if any,
|
|
// and put these exports in the appropriate place for that loader.
|
|
var exportTo = {};
|
|
|
|
// According to the Closure team, their polyfills will be written to
|
|
// $jscomp.global, which will be "window", or "global", or "this", depending
|
|
// on circumstances.
|
|
// See https://github.com/google/closure-compiler/issues/2957 and
|
|
// https://github.com/google/shaka-player/issues/1455#issuecomment-393250035
|
|
|
|
// We provide "global" for use by Closure, and "window" for use by the Shaka
|
|
// library itself. Both point to "innerGlobal" above.
|
|
(function(window, global) {
|
|
|
|
%output%
|
|
|
|
}).call(exportTo, innerGlobal, innerGlobal);
|
|
|
|
if (typeof exports != 'undefined') {
|
|
// CommonJS module loader. Use "exports" instead of "module.exports" to
|
|
// avoid triggering inappropriately in Electron.
|
|
for (var k in exportTo.shaka) {
|
|
exports[k] = exportTo.shaka[k];
|
|
}
|
|
} else if (typeof define != 'undefined' && define.amd) {
|
|
// AMD module loader.
|
|
define(function(){
|
|
return exportTo.shaka;
|
|
});
|
|
} else {
|
|
// Loaded as an ES module or directly in a <script> tag.
|
|
// Export directly to the global scope.
|
|
innerGlobal.shaka = exportTo.shaka;
|
|
}
|
|
})();
|