🎥 Make videos programmatically with React
Docs: Integration into other frameworks
Simon Lehmanna5884c8f4118
diff --git a/packages/docs/docs/integration-frameworks/angular.mdx b/packages/docs/docs/integration-frameworks/angular.mdxnew file mode 100644index 0000000000..bd43bd31c1--- /dev/null+++ b/packages/docs/docs/integration-frameworks/angular.mdx@@ -0,0 +1,289 @@+---+image: /generated/articles-docs-integration-frameworks-angular.png+id: angular+sidebar_label: 'Angular'+title: 'Angular'+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++# Using Remotion with Angular++This guide explains how to integrate **Remotion** into an **Angular** project.+++## Install required packages++Install Remotion and necessary dependencies:++<Tabs+defaultValue="npm"+values={[+{ label: 'npm', value: 'npm', },+{ label: 'pnpm', value: 'pnpm', },+{ label: 'yarn', value: 'yarn', },+{ label: 'bun', value: 'bun', },+]+}>+<TabItem value="npm">++```bash title="Use npm as the package manager"+npm i remotion @remotion/player @remotion/cli @remotion/zod-types react react-dom zod+npm i --save-dev @types/react @types/react-dom+```++ </TabItem>+ <TabItem value="pnpm">++```bash title="Use pnpm as the package manager"+pnpm i remotion @remotion/player @remotion/cli @remotion/zod-types react react-dom zod+pnpm i --dev @types/react @types/react-dom+```++ </TabItem>++ <TabItem value="yarn">++```bash title="Use Yarn as the package manager"+yarn add remotion @remotion/player @remotion/cli @remotion/zod-types react react-dom zod+yarn add --dev @types/react @types/react-dom+```++ </TabItem>++ <TabItem value="bun">++```bash title="Use Bun as the package manager and runtime"+bun i remotion @remotion/player @remotion/cli @remotion/zod-types react react-dom zod+bun --dev @types/react @types/react-dom+```++:::note+Bun as a runtime is mostly supported. [Read more here](/docs/bun).+:::++ </TabItem>+</Tabs>++## Create a Remotion folder++For better separation, create a folder to hold your Remotion files:++```plaintext+src/app/remotion+```++Copy the contents of your Remotion project or a starter template (e.g., HelloWorld) into this new folder. This will help separate Remotion related files from the rest of your Angular codebase.++## Copy `remotion.config.ts`++Copy the `remotion.config.ts` file to the root directory of your Angular project, placing it at the same level as `package.json`.++This configuration file is necessary for Remotion to recognize and compile your project settings.++## Configure TypeScript for JSX++To enable JSX support in Angular, update the `tsconfig.json` file by setting `"jsx": "react"` under `compilerOptions`. This configuration allows Angular to interpret JSX syntax used in Remotion's React components.++```json title="tsconfig.json"+{+ "compilerOptions": {+ "jsx": "react",+ "skipLibCheck": true, // Recommended to avoid errors with certain libraries+ // other options+ }+}+```++:::note+The "skipLibCheck": true setting is also recommended to prevent compatibility issues with certain library types.+:::++## Create a React wrapper component for Angular++To embed Remotion components in Angular, create a **wrapper component**:++1. In your `remotion` folder, create a file named `PlayerViewWrapper.tsx`.+2. Ensure each `.tsx` file imports React explicitly at the top of the file:++```tsx title="PlayerViewWrapper.tsx"+import {AfterViewInit, Component, effect, ElementRef, EventEmitter, Input, OnDestroy, Output, signal, Signal, ViewChild, WritableSignal} from '@angular/core';+import {CommonModule} from '@angular/common';+import {RouterOutlet} from '@angular/router';+import React from 'react';+import {createRoot, Root} from "react-dom/client";+import {PlayerRef} from "@remotion/player";+import {myCompSchema, PlayerView} from "./PlayerView";+import {z} from "zod";++const rootDomID: string = "reactCounterWrapperId";++@Component({+ selector: 'app-player-view',+ standalone: true,+ imports: [CommonModule, RouterOutlet],+ template: `+ <div id="${rootDomID}" #${rootDomID}></div>`,+})+export class PlayerViewWrapper implements AfterViewInit, OnDestroy {+ @ViewChild(rootDomID, {static: false}) containerRef: ElementRef | undefined;+ @Input({required: true}) data: Signal<z.infer<typeof myCompSchema>> = signal({+ titleText: "Welcome to Remotion",+ titleColor: "#000000",+ logoColor1: "#91EAE4",+ logoColor2: "#86A8E7",+ })+ @Output() onPaused = new EventEmitter<void>+ playerRef: WritableSignal<PlayerRef | undefined> = signal(undefined);++ private root?: Root++ constructor() {+ effect(() => {+ this.render()+ })+ }++ ngAfterViewInit() {+ this.root = createRoot(this.getRootDomNode())+ this.render();+ this.playerRef()?.play()+ }++ ngOnDestroy(): void {+ this.root?.unmount()+ }++ private getRootDomNode() {+ if (!this.containerRef || !this.containerRef.nativeElement) {+ throw new Error("Cannot get root element. This should not happen.");+ }+ return this.containerRef.nativeElement;+ }++ protected render() {+ if (!this.containerRef || !this.containerRef.nativeElement) return;+ this.root?.render(<PlayerView playerRefInstance={this.playerRef} data={this.data()} onPaused={() => this.onPaused.emit()} />)+ }+}+```++This wrapper component will serve as the bridge between Angular and Remotion’s React components.++You can also pass an EventEmitter instead of a Signal.++## Create a wrapper for the Remotion player++1. In your `remotion` folder, create a file named `PlayerView.tsx`.+2. Ensure each `.tsx` file imports React explicitly at the top of the file:++This will get the reference to the player with `useRef`.++```tsx title="PlayerView.tsx"+import React, {useEffect} from "react";+import {Player, PlayerRef} from "@remotion/player";+import {z} from "zod";+import {HelloWorld} from "./HelloWorld";+import {zColor} from "@remotion/zod-types";+import {WritableSignal} from "@angular/core";++export const PlayerView: React.FC<{ data: z.infer<typeof myCompSchema>, playerRefInstance: WritableSignal<PlayerRef | undefined>, onPaused?: () => void }> = ({data, playerRefInstance, onPaused}) => {++ const playerRef: React.RefObject<PlayerRef> = React.createRef()++ useEffect(() => {+ if (playerRef.current) {+ playerRefInstance.set(playerRef.current)++ // add callback when player pauses+ playerRef.current.addEventListener('pause', () => {+ onPaused?.()+ })+ }+ }, [])+ return <Player+ ref={playerRef}+ component={HelloWorld}+ durationInFrames={150}+ fps={30}+ compositionHeight={1080}+ compositionWidth={1920}+ inputProps={data}+ controls+ />+}+```++## Use the component in Angular++To display the Remotion player within an Angular template, add your new wrapper component wherever you'd like the player to appear:++```html+<app-player-view [data]="data" (onPaused)="playerPaused()"></app-player-view>+```++This Angular component tag will render the Remotion player, allowing you to pass data or configuration as needed through Angular's data binding.++You're no able to use the [`API`](/docs/player/player) of the player via `this.playerRef()`++## Configure TailwindCSS (optional)++If your project uses **TailwindCSS**, ensure that it applies styles to `.tsx` files by updating the `tailwind.config.js` file as follows:++```js title="tailwind.config.js"+module.exports = {+ content: [+ './src/**/*.{html,ts,tsx}', // Add .tsx files to Tailwind content paths+ // other paths+ ],+ // other Tailwind configurations+};+```++You should also install the following package:++<Tabs+defaultValue="npm"+values={[+{ label: 'npm', value: 'npm', },+{ label: 'pnpm', value: 'pnpm', },+{ label: 'yarn', value: 'yarn', },+{ label: 'bun', value: 'bun', },+]+}>+<TabItem value="npm">++```bash title="Use npm as the package manager"+npm i @remotion/tailwind+```++ </TabItem>+ <TabItem value="pnpm">++```bash title="Use pnpm as the package manager"+pnpm i @remotion/tailwind+```++ </TabItem>++ <TabItem value="yarn">++```bash title="Use Yarn as the package manager"+yarn add @remotion/tailwind+```++ </TabItem>++ <TabItem value="bun">++```bash title="Use Bun as the package manager and runtime"+bun i @remotion/tailwind+```++:::note+Bun as a runtime is mostly supported. [Read more here](/docs/bun).+:::++ </TabItem>+</Tabs>diff --git a/packages/docs/docs/integration-frameworks/vue-js.mdx b/packages/docs/docs/integration-frameworks/vue-js.mdxnew file mode 100644index 0000000000..8b1ab61fa6--- /dev/null+++ b/packages/docs/docs/integration-frameworks/vue-js.mdx@@ -0,0 +1,306 @@+---+image: /generated/articles-docs-integration-frameworks-vue-js.png+id: vue-js+sidebar_label: 'VueJS'+title: 'VueJS'+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++# Using Remotion with VueJS++This guide explains how to integrate **Remotion** into a **VueJS** project.+++## Install required packages++Install Remotion and necessary dependencies:++<Tabs+defaultValue="npm"+values={[+{ label: 'npm', value: 'npm', },+{ label: 'pnpm', value: 'pnpm', },+{ label: 'yarn', value: 'yarn', },+{ label: 'bun', value: 'bun', },+]+}>+<TabItem value="npm">++```bash title="Use npm as the package manager"+npm i remotion @remotion/player @remotion/cli react react-dom+npm i --save-dev @types/react @types/react-dom @vitejs/plugin-react+```++ </TabItem>+ <TabItem value="pnpm">++```bash title="Use pnpm as the package manager"+pnpm i remotion @remotion/player @remotion/cli react react-dom+pnpm i --dev @types/react @types/react-dom @vitejs/plugin-react+```++ </TabItem>++ <TabItem value="yarn">++```bash title="Use Yarn as the package manager"+yarn add remotion @remotion/player @remotion/cli react react-dom+yarn add --dev @types/react @types/react-dom @vitejs/plugin-react+```++ </TabItem>++ <TabItem value="bun">++```bash title="Use Bun as the package manager and runtime"+bun i remotion @remotion/player @remotion/cli react react-dom+bun --dev @types/react @types/react-dom @vitejs/plugin-react+```++:::note+Bun as a runtime is mostly supported. [Read more here](/docs/bun).+:::++ </TabItem>+</Tabs>++## Create a Remotion folder++For better separation, create a folder to hold your Remotion files:++```plaintext+src/remotion+```++Copy the contents of your Remotion project or a starter template (e.g., HelloWorld) into this new folder. This will help separate Remotion related files from the rest of your VueJS codebase.++## Copy `remotion.config.ts`++Copy the `remotion.config.ts` file to the root directory of your VueJS project, placing it at the same level as `package.json`.++This configuration file is necessary for Remotion to recognize and compile your project settings.++## Configure TypeScript for JSX++To enable JSX support in VueJS, update the `tsconfig.app.json` file by setting `"jsx": "react"` under `compilerOptions`. This configuration allows VueJS to interpret JSX syntax used in Remotion's React components.++```json title="tsconfig.json"+{+ "compilerOptions": {+ "jsx": "react",+ "jsxImportSource": "", // Recommended to avoid errors while building+ // other options+ }+}+```+:::note+The "jsxImportSource": "" setting is also recommended to prevent build issues.+:::++## Configure Vite for React++To enable React support in Vite, update the `vite.config.ts` file by setting adding react to the plugins.++```ts title="vite.config.ts"+import { fileURLToPath, URL } from 'node:url'+import { defineConfig } from 'vite'+import vue from '@vitejs/plugin-vue'+import react from '@vitejs/plugin-react'++export default defineConfig({+ plugins: [+ vue(),+ react({+ include: /\.(jsx|tsx)$/,+ }),+ ],+ resolve: {+ alias: {+ '@': fileURLToPath(new URL('./src', import.meta.url))+ },+ },+})+```++## Create a React wrapper component for VueJS++To embed Remotion components in VueJS, create a **wrapper component**:++1. In your `remotion` folder, create a file named `PlayerViewWrapper.vue`.++```ts title="PlayerViewWrapper.vue"+<script lang="ts" setup>+ import {onBeforeUnmount, onMounted, ref, watch} from 'vue';+ import {type PlayerSchema, PlayerView} from "@/remotion/PlayerView";+ import {createRoot, type Root} from "react-dom/client";+ import * as React from "react";++ interface PlayerData {+ data: PlayerSchema;+ }++ const playerRef = ref()+ const reactRoot = ref();+ let root: Root;+ const emit = defineEmits(['paused'])++ const props = defineProps<PlayerData>()++ onMounted(() => {+ root = createRoot(reactRoot.value);+ render()+ });++ function render() {+ root.render(React.createElement(PlayerView, {+ data: props.data,+ playerRefInstance: playerRef,+ onPaused: () => emit('paused'),+ }));+ }++ watch(() => playerRef, (newData, oldData) => {+ playerRef.value.play();+ }, {deep: true})++ watch(() => props.data, (newData, oldData) => {+ render()+ }, {deep: true})++ onBeforeUnmount(() => {+ if (root) {+ root.unmount();+ }+ });+</script>++<template>+ <div ref="reactRoot"></div>+</template>+```++This wrapper component will serve as the bridge between VueJs and Remotion’s React components.++## Create a wrapper for the Remotion player++1. In your `remotion` folder, create a file named `PlayerView.tsx`.+2. Ensure each `.tsx` file imports React explicitly at the top of the file:++This will get the reference to the player with `useRef`.++```tsx title="PlayerView.tsx"+import React, {useEffect} from "react";+import {Player, type PlayerRef} from "@remotion/player";+import {HelloWorld} from "@/remotion/HelloWorld";+import type {Ref} from "vue";++export interface PlayerSchema {+ titleText: string+ titleColor: string+ logoColor1: string+ logoColor2: string+}++export const PlayerView = ({data, playerRefInstance, onPaused}: { data: PlayerSchema, playerRefInstance: Ref<PlayerRef>, onPaused?: () => void }): React.ReactElement => {++ const playerRef: React.RefObject<PlayerRef> = React.createRef()++ useEffect(() => {+ if (playerRef.current) {+ playerRefInstance.value = playerRef.current++ // add callback when player pauses+ playerRef.current.addEventListener('pause', () => {+ onPaused?.()+ })+ }+ }, [])++ return <Player+ ref={playerRef}+ component={HelloWorld}+ durationInFrames={150}+ fps={30}+ compositionHeight={1080}+ compositionWidth={1920}+ inputProps={data}+ controls+ />+}+```++## Use the component in VueJS++To display the Remotion player within an VueJS template, add your new wrapper component wherever you'd like the player to appear:++```html+<PlayerWrapper @paused=onPaused :data="data" />+```++This VueJS component tag will render the Remotion player, allowing you to pass data or configuration as needed through VueJS's data binding.++You're no able to use the [`API`](/docs/player/player) of the player via `this.playerRef()`++## Configure TailwindCSS (optional)++If your project uses **TailwindCSS**, ensure that it applies styles to `.tsx` files by updating the `tailwind.config.js` file as follows:++```js title="tailwind.config.js"+module.exports = {+ content: [+ "./index.html",+ "./src/**/*.{vue,tsx}",, // Add .tsx files to Tailwind content paths+ // other paths+ ],+ // other Tailwind configurations+};+```++You should also install the following package:++<Tabs+defaultValue="npm"+values={[+{ label: 'npm', value: 'npm', },+{ label: 'pnpm', value: 'pnpm', },+{ label: 'yarn', value: 'yarn', },+{ label: 'bun', value: 'bun', },+]+}>+<TabItem value="npm">++```bash title="Use npm as the package manager"+npm i @remotion/tailwind+```++ </TabItem>+ <TabItem value="pnpm">++```bash title="Use pnpm as the package manager"+pnpm i @remotion/tailwind+```++ </TabItem>++ <TabItem value="yarn">++```bash title="Use Yarn as the package manager"+yarn add @remotion/tailwind+```++ </TabItem>++ <TabItem value="bun">++```bash title="Use Bun as the package manager and runtime"+bun i @remotion/tailwind+```++:::note+Bun as a runtime is mostly supported. [Read more here](/docs/bun).+:::++ </TabItem>+</Tabs>diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 7b7fd7bf0c..f07dd5ca04 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -851,6 +851,14 @@ module.exports = {'multiple-fps',],},+ {+ type: 'category',+ label: 'Integration into other frameworks',+ items: [+ 'integration-frameworks/angular',+ 'integration-frameworks/vue-js',+ ],+ },{type: 'category',label: 'Tooling',diff --git a/packages/docs/static/generated/articles-docs-integration-frameworks-angular.png b/packages/docs/static/generated/articles-docs-integration-frameworks-angular.pngnew file mode 100644index 0000000000..ca278f2b8cBinary files /dev/null and b/packages/docs/static/generated/articles-docs-integration-frameworks-angular.png differdiff --git a/packages/docs/static/generated/articles-docs-integration-frameworks-vue-js.png b/packages/docs/static/generated/articles-docs-integration-frameworks-vue-js.pngnew file mode 100644index 0000000000..fe1ee1740cBinary files /dev/null and b/packages/docs/static/generated/articles-docs-integration-frameworks-vue-js.png differ