为基于 TVML 的 Apple TV 应用程序使用外部 javascript 库?

Use external javascript libraries for TVML based Apple TV apps?

是否可以加载和使用外部 javascript 库以用于 TVML Apple TV 应用程序?

例如,我可以加载 Firebase js 库并使用它来获取数据吗?或者加载 lodash 以使用它的功能?

您可以使用 evaluateScript 函数加载外部 JavaScript 库。

evaluateScripts([“ARRAY OF JS URLS”], function(success) {

// do work here once the JavaScript files have been evaluated

})

我很幸运地使用 webpack 将我所有的依赖项打包到一个缩小的 application.js 文件中。 Webpack 将处理捆绑所需的 commonjs 模块和第三方库,您可以使用 babel-loader 添加缺少的 es6 支持(import/export、const/let、箭头函数等)。

这是我的 application.js:

require('babel-polyfill');
import Presenter from './presenter';
import ResourceLoader from './resourceLoader';

App.onLaunch = function(options) {
  let resourceLoader = new ResourceLoader(options.BASEURL);

  Presenter.resourceLoader = resourceLoader;

  let index = resourceLoader.loadResource(`${options.BASEURL}templates/Index.xml.js`, (resource) => {
    let doc = Presenter.makeDocument(resource);
    doc.addEventListener('select', Presenter.load.bind(Presenter));
    navigationDocument.pushDocument(doc);
  });
}

和我的 webpack.config.js:

var webpack = require('webpack');

module.exports = {
  entry: "./src/js/application.js",
  output: {
      path: __dirname + "/public/js",
      filename: "application.js"
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
          cacheDirectory: true,
          presets: ['es2015']
        }
      }
    ]
  }
};

https://github.com/emadalam/tvml-catalog-using-atvjs

参考此移植的原始示例代码使用atvjs framework that is using external libraries like Handlebars, lodash, atvjs等重写