Is it possible to load and use external javascript libraries for use on TVML Apple TV apps?
For example, can I load the Firebase js library and use it to fetch data? Or load lodash to use it's functions?
Is it possible to load and use external javascript libraries for use on TVML Apple TV apps?
For example, can I load the Firebase js library and use it to fetch data? Or load lodash to use it's functions?
You can load external JavaScript libraries using the evaluateScript function.
evaluateScripts([“ARRAY OF JS URLS”], function(success) {
// do work here once the JavaScript files have been evaluated
})
I've had luck using webpack to package all of my dependencies into a single minified application.js file. Webpack will handle bundling required commonjs modules and third-party libraries and you can use babel-loader to add missing es6 support (import/export, const/let, arrow functions, etc).
Here's my 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);
});
}
and my 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']
}
}
]
}
};
evaluateScripts
is very limiting. However, I do have the same question as @zfu: how do you debug a webpack output? –
Harrietharriett devtool: "inline-source-map"
in webpack's configuration. –
Dunlop App
is exposed as a module instead of code that is executed. How did you workaround this? –
Fob https://github.com/emadalam/tvml-catalog-using-atvjs
Refer to this port of the original sample code re-written using atvjs framework that is using external libraries like Handlebars, lodash, atvjs etc.
© 2022 - 2024 — McMap. All rights reserved.