7

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

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

4

3 回答 3

7

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

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

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

})
于 2015-09-14T03:33:44.930 回答
6

我很幸运使用 webpack 将我的所有依赖项打包到一个缩小的 application.js 文件中。Webpack 将处理捆绑所需的 commonjs 模块和第三方库,您可以使用 babel-loader 添加缺少的 es6 支持(导入/导出、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']
        }
      }
    ]
  }
};
于 2015-11-04T22:58:22.667 回答
0

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

请参阅使用atvjs框架重新编写的原始示例代码的此端口,该框架使用外部库,如Handlebarslodashatvjs等。

于 2016-01-30T21:23:24.460 回答