TailwindCSS
Using the template
The easiest way to get started with Tailwind and Remotion is to use the template by cloning it on GitHub or running the following:
- npm
- yarn
- pnpm
bash
npx create-video --tailwind
bash
npx create-video --tailwind
bash
pnpm create video --tailwind
bash
pnpm create video --tailwind
bash
yarn create video -- --tailwind
bash
yarn create video -- --tailwind
Install in existing project
- Install the following dependencies:
- npm
- yarn
- pnpm
bash
npm i -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
bash
npm i -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
bash
yarn add -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
bash
yarn add -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
bash
pnpm i -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
bash
pnpm i -D postcss-loader postcss postcss-preset-env tailwindcss autoprefixer css-loader style-loader
- Create a function for overriding the webpack config
src/enable-tailwind.tsts
import {WebpackOverrideFn } from "@remotion/bundler";export constenableTailwind :WebpackOverrideFn = (currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []).filter ((rule ) => {if (rule === "...") {return false;}if (rule .test ?.toString ().includes (".css")) {return false;}return true;}),{test : /\.css$/i,use : ["style-loader","css-loader",{loader : "postcss-loader",options : {postcssOptions : {plugins : ["postcss-preset-env","tailwindcss","autoprefixer",],},},},],},],},};};
src/enable-tailwind.tsts
import {WebpackOverrideFn } from "@remotion/bundler";export constenableTailwind :WebpackOverrideFn = (currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []).filter ((rule ) => {if (rule === "...") {return false;}if (rule .test ?.toString ().includes (".css")) {return false;}return true;}),{test : /\.css$/i,use : ["style-loader","css-loader",{loader : "postcss-loader",options : {postcssOptions : {plugins : ["postcss-preset-env","tailwindcss","autoprefixer",],},},},],},],},};};
- Add the Webpack override to your config file:
remotion.config.tsts
import {Config } from "remotion";import {enableTailwind } from "./src/enable-tailwind";Config .overrideWebpackConfig (enableTailwind );
remotion.config.tsts
import {Config } from "remotion";import {enableTailwind } from "./src/enable-tailwind";Config .overrideWebpackConfig (enableTailwind );
note
Prior to v3.3.39
, the option was called Config.Bundling.overrideWebpackConfig()
.
If you use the
bundle()
ordeploySite()
Node.JS API, add the Webpack override to it as well.Create a file
src/style.css
with the following content:
src/style.csscss
@tailwind base;@tailwind components;@tailwind utilities;
src/style.csscss
@tailwind base;@tailwind components;@tailwind utilities;
- Import the stylesheet in your
src/Root.tsx
file. Add to the top of the file:
src/Root.tsxjs
import "./style.css";
src/Root.tsxjs
import "./style.css";
- Add a
tailwind.config.js
file to the root of your project:
tailwind.config.jsjs
/* eslint-env node */module.exports = {content: ["./src/**/*.{ts,tsx}"],theme: {extend: {},},plugins: [],};
tailwind.config.jsjs
/* eslint-env node */module.exports = {content: ["./src/**/*.{ts,tsx}"],theme: {extend: {},},plugins: [],};
- Ensure your
package.json
does not have"sideEffects": false
set. If it has, declare that CSS files have a side effect:
package.jsondiff
{// Only if `"sideEffects": false` exists in your package.json.- "sideEffects": false+ "sideEffects": ["*.css"]}
package.jsondiff
{// Only if `"sideEffects": false` exists in your package.json.- "sideEffects": false+ "sideEffects": ["*.css"]}
- Start using TailwindCSS! You can verify that it's working by adding
className="bg-red-900"
to any element.