如何将 YouTube API 与 Gulp 一起使用(缩小文件不包含 YouTube 回调方法)

How to use YouTube API with Gulp (minified file doesn't contain YouTube callback methods)

我无法在缩小的 .js 文件中使用 YouTube Player API methods because they are deleted by Laravel Elixir (Gulp)。

我的缩小 .js 文件中不包含如下方法,因为它们未在我创建的 .js 文件中调用(事实上,它们在 YouTube iFrame API 中调用).

onYouTubeIframeAPIReady
onPlayerReady
onPlayerStateChange

这个问题有什么解决办法吗?

唯一的解决办法是调用 onYouTubeIframeAPIReady()

为此,我添加了一个条件:

function onYouTubeIframeAPIReady(init) {
   if (init === "init") {
       return;
   }
   // Init your YouTube Player here, after the condition.
}

// First call here : The minifier notices the method is used, so it won't delete it
onYouTubeIframeAPIReady("init");

// Later, YouTube API will call this method
// (YouTube doesn't pass any parameters, so the player will be initialized in this case)
// YouTube API : onYouTubeIframeAPIReady();