Custom Webpack config
You can customize the Webpack configuration if you have at least Version 1.1 of Remotion.
Create a config file called remotion.config.ts
in the root of your project. As a confirmation, you should get a console message Applied configuration from [configuration-file]
.
Overriding the webpack config
Get familiar with the default Webpack configuration which can be found here.
In your remotion.config.ts
file, you can call Config.Bundler.overrideWebpackConfig
from remotion
.
Overriding the Webpack config uses the reducer pattern - pass in a function that takes as it's argument a Webpack configuration and return a new Webpack configuration.
ts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?? []),// Add more loaders here],},};});
ts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?? []),// Add more loaders here],},};});
info
Using the reducer pattern will help with type safety, give you auto-complete, ensure forwards-compatibility and keep it completely flexible - you can override just one property or pass in a completely new Webpack configuration.
Snippets
Enabling MDX support
The following remotion.config.ts
file shows how to enable support for MDX. Installation of mdx-loader babel-loader @babel/preset-env @babel/preset-react
is required.
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.mdx?$/,use : [{loader : "babel-loader",options : {presets : ["@babel/preset-env",["@babel/preset-react",{runtime : "automatic",},],],},},"mdx-loader",],},],},};});
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.mdx?$/,use : [{loader : "babel-loader",options : {presets : ["@babel/preset-env",["@babel/preset-react",{runtime : "automatic",},],],},},"mdx-loader",],},],},};});
info
Create a file which contains declare module '*.mdx';
in your project to fix a TypeScript error showing up.
Enable TailwindCSS support
Enable SASS/SCSS support
- Install the following dependencies:
- npm
- yarn
- pnpm
bash
npm i sass sass-loader
bash
npm i sass sass-loader
bash
pnpm i sass sass-loader
bash
pnpm i sass sass-loader
bash
yarn add sass sass-loader
bash
yarn add sass sass-loader
- Add the following to your
remotion.config.ts
file:
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.s[ac]ss$/i,use : [{loader : "style-loader" },{loader : "css-loader" },{loader : "sass-loader",options : {sourceMap : true } },],},],},};});
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.s[ac]ss$/i,use : [{loader : "style-loader" },{loader : "css-loader" },{loader : "sass-loader",options : {sourceMap : true } },],},],},};});
- Restart the preview server.
Enable support for GLSL imports
- Install the following dependencies:
- npm
- yarn
- pnpm
bash
npm i glsl-shader-loader glslify glslify-import-loader raw-roader
bash
npm i glsl-shader-loader glslify glslify-import-loader raw-roader
bash
yarn add glsl-shader-loader glslify glslify-import-loader raw-roader
bash
yarn add glsl-shader-loader glslify glslify-import-loader raw-roader
bash
pnpm i glsl-shader-loader glslify glslify-import-loader raw-roader
bash
pnpm i glsl-shader-loader glslify glslify-import-loader raw-roader
- Add the following to your
remotion.config.ts
file:
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.(glsl|vs|fs|vert|frag)$/,exclude : /node_modules/,use : ["glslify-import-loader", "raw-loader", "glslify-loader"],},],},};});
ts
Config .Bundling .overrideWebpackConfig ((currentConfiguration ) => {return {...currentConfiguration ,module : {...currentConfiguration .module ,rules : [...(currentConfiguration .module ?.rules ?currentConfiguration .module .rules : []),{test : /\.(glsl|vs|fs|vert|frag)$/,exclude : /node_modules/,use : ["glslify-import-loader", "raw-loader", "glslify-loader"],},],},};});
- Add the following to your entry file (e.g.
src/index.tsx
):
ts
declare module "*.glsl" {const value: string;export default value;}
ts
declare module "*.glsl" {const value: string;export default value;}
- Reset the webpack cache by deleting the
node_modules/.cache
folder. - Restart the preview server.
Enable WebAssembly
There are two WebAssembly modes: asynchronous and synchronous. We recommend testing both and seeing which one works for the WASM library you are trying to use.
remotion.config.ts - synchronousts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((conf ) => {return {...conf ,experiments : {syncWebAssembly : true,},};});
remotion.config.ts - synchronousts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((conf ) => {return {...conf ,experiments : {syncWebAssembly : true,},};});
note
Since Webpack does not allow synchronous WebAssembly code in the main chunk, you most likely need to declare your composition using lazyComponent
instead of component
. Check out a demo project for an example.
remotion.config.ts - asynchronousts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((conf ) => {return {...conf ,experiments : {asyncWebAssembly : true,},};});
remotion.config.ts - asynchronousts
import {Config } from "remotion";Config .Bundling .overrideWebpackConfig ((conf ) => {return {...conf ,experiments : {asyncWebAssembly : true,},};});
After you've done that, clear the Webpack cache:
bash
rm -rf node_modules/.cache
bash
rm -rf node_modules/.cache
After restarting, you can import .wasm
files using an import statement.
Use legacy babel loader
See Using legacy Babel transpilation.
Enable TypeScript aliases
See TypeScript aliases.
Customizing configuration file location
You can pass a --config
option to the command line to specify a custom location for your configuration file.