Version: 3.0
Date: February 7, 2026
Status: Universal Runtime
- Overview
- Requirements
- Rollup Configuration
- Version Injection
- Build Scripts
- Bundle Output
- Development Workflow
- Deployment
- Troubleshooting
TizenPortal uses Rollup with Babel to bundle ES6+ source code into an ES5-compatible IIFE that runs on Samsung Tizen TVs (Chrome 47-69).
The build system produces one universal output:
| Output | Input | Size | Purpose |
|---|---|---|---|
dist/tizenportal.js |
core/index.js |
~320KB | Universal runtime for portal and target sites |
TizenPortal operates as a TizenBrew MOD module with a unified runtime:
- TizenBrew injects
tizenportal.jsinto ALL pages - On portal page: Runtime renders launcher UI
- On target sites: Runtime applies bundles and overlays
The same script runs everywhere, detecting context automatically.
- Minimum: Node 18.x
- Recommended: Node 20.x LTS
- npm (comes with Node.js)
{
"devDependencies": {
"rollup": "^4.0.0",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-replace": "^6.0.3",
"@rollup/plugin-terser": "^0.4.0",
"@babel/core": "^7.23.0",
"@babel/preset-env": "^7.23.0",
"rollup-plugin-string": "^3.0.0"
},
"dependencies": {
"core-js": "^3.47.0",
"whatwg-fetch": "^3.6.20",
"spatial-navigation-polyfill": "^1.3.1"
}
}npm installThe configuration builds a single universal runtime:
// rollup.config.js
import { string } from 'rollup-plugin-string';
import terser from '@rollup/plugin-terser';
import babel from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import { readFileSync } from 'fs';
// Read version from package.json - single source of truth
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
const VERSION = pkg.version;
// Shared plugins
const plugins = [
// Replace __VERSION__ placeholder with actual version
replace({
preventAssignment: true,
values: { '__VERSION__': VERSION },
}),
// Import CSS files as strings
string({ include: '**/*.css' }),
// Resolve node_modules imports
nodeResolve({ browser: true, preferBuiltins: false }),
// Convert CommonJS modules to ES modules
commonjs({ include: [/node_modules/], transformMixedEsModules: true }),
// Transpile to ES5 for Chrome 47+ compatibility
babel({
babelHelpers: 'bundled',
presets: [['@babel/preset-env', { targets: { chrome: '47' }, modules: false }]],
exclude: 'node_modules/**',
}),
// Minify output
terser({ ecma: 5, mangle: true, compress: { drop_console: false } }),
];
export default [
// Single build: Universal runtime
{
input: 'core/index.js',
output: {
file: 'dist/tizenportal.js',
format: 'iife',
name: 'TizenPortal',
sourcemap: false,
},
plugins,
},
];| Plugin | Purpose |
|---|---|
@rollup/plugin-replace |
Inject version from package.json at build time |
rollup-plugin-string |
Import CSS files as strings |
@rollup/plugin-node-resolve |
Resolve imports from node_modules |
@rollup/plugin-commonjs |
Convert CommonJS to ES modules |
@rollup/plugin-babel |
Transpile ES6+ syntax to ES5 |
@rollup/plugin-terser |
Minify output |
Version is centralized in package.json and injected at build time.
- package.json holds the single source of truth:
{ "version": "XXYY" } // e.g., "1018" for v1.0.18
2. **Rollup reads** the version at build time:
```js
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
const VERSION = pkg.version;
-
Replace plugin substitutes
__VERSION__in source code:replace({ values: { '__VERSION__': VERSION } })
-
Source files use the placeholder:
const VERSION = 'VERSION'; // Replaced with package.json version at build time
### Benefits
- Only update version in one place
- Git tags match package.json version
- Build artifacts always have current version
- No manual synchronization needed
---
## 5. Build Scripts
Defined in `package.json`:
```json
{
"scripts": {
"build": "rollup -c",
"watch": "rollup -c --watch",
"clean": "node -e \"require('fs').rmSync('dist/tizenportal.js', {force: true})\""
}
}
| Command | Purpose |
|---|---|
npm run build |
Production build (minified) |
npm run watch |
Development with auto-rebuild |
npm run clean |
Remove built files |
dist/
├── index.html # Portal HTML (manually maintained)
└── tizenportal.js # Built runtime (~320KB minified)
// dist/tizenportal.js (IIFE format)
var TizenPortal = (function () {
'use strict';
// Polyfills (core-js, fetch, DOMRect)
// Spatial navigation polyfill
// Configuration system
// Input handling
// Focus management
// UI components
// Bundle registry
// Core initialization
return {
version: 'XXYY', // Injected from package.json at build time
config: {...},
input: {...},
focus: {...},
keys: {...},
log: function() {...},
// ... more exports
};
})();| Metric | Target | Actual |
|---|---|---|
| Minified | < 400KB | ~320KB |
| Gzipped | < 100KB | ~80KB |
The build includes:
- Polyfills (core-js, fetch, DOMRect)
- Spatial Navigation polyfill
- Core Modules (config, cards, loader)
- UI Components (portal, siteeditor, overlays)
- Input Handling (keys, pointer, text-input)
- Focus Management
- Diagnostics (console capture)
- Bundles (default, audiobookshelf, adblock)
# 1. Start watch mode
npm run watch
# 2. Edit source files
# 3. Build auto-runs on save
# 4. Test on TV or emulator- Edit source files in
core/,ui/,bundles/, etc. - Rollup rebuilds automatically in watch mode
- Deploy
dist/folder to test
- Create bundle folder:
bundles/my-bundle/ - Add
main.js,style.css,manifest.json - Register in
bundles/registry.js - Rebuild:
npm run build
Since the runtime is injected by TizenBrew, local testing requires:
- TizenBrew on TV - Deploy to GitHub Pages
- Browser Testing - Open
dist/index.htmllocally for portal UI - Emulator - Samsung Tizen Studio emulator
# 1. Update version in package.json
"version": "0392"
# 2. Rebuild
npm run build
# 3. Commit and tag
git add .
git commit -m "Bump to 0392"
git tag 0392
git push origin master --tagsThe dist/ folder is deployed to GitHub Pages:
https://axelnanol.github.io/tizenportal/dist/index.html
https://axelnanol.github.io/tizenportal/dist/tizenportal.js
TizenBrew caches by git tag. To update:
- Create new git tag (e.g.,
0392) - Push tag to GitHub
- On TV: Remove old module, add new version
Important: Without a new tag, TizenBrew serves cached old code!
# Clear node_modules and rebuild
rm -rf node_modules
npm install
npm run build- Check package.json version
- Rebuild:
npm run build - Verify in output:
grep "version" dist/tizenportal.js
- Verify bundle is in
bundles/folder - Check import in
bundles/registry.js - Verify no syntax errors in bundle code
- Rebuild and check console for errors
- Enable diagnostics (Blue button)
- Check for ES5 incompatible code
- Wrap suspicious code in try-catch
- Test specific code in Chrome 47 DevTools
- Check for duplicate imports
- Review polyfill inclusion
- Consider code splitting (future)
- Use tree-shaking hints
CSS files are imported as strings:
// In bundle main.js
import styles from './style.css';
export default {
style: styles, // String of CSS content
// ...
};The rollup-plugin-string plugin handles this.
Babel transpiles modern JavaScript:
| ES6+ Feature | ES5 Output |
|---|---|
| Arrow functions | Regular functions |
| const/let | var |
| Classes | Constructor functions |
| Template literals | String concatenation |
| Spread operator | Array.concat / Object.assign |
| Async/await | Not supported (avoid using) |
Via core-js and whatwg-fetch:
PromiseObject.assignArray.from,Array.ofArray.prototype.find,findIndexString.prototype.includesfetchAPI- And many more ES6+ features
End of Build System Documentation