Skip to main content

Custom Webpack config

Remotion ships with it's own Webpack configuration.

You can override it reducer-style by creating a function that takes the previous Webpack configuration and returns the the new one.

When rendering using the command line

In your remotion.config.ts file, you can call Config.Bundler.overrideWebpackConfig() from remotion.

remotion.config.ts
ts
import { Config } from "remotion";
 
Config.Bundling.overrideWebpackConfig((currentConfiguration) => {
return {
...currentConfiguration,
module: {
...currentConfiguration.module,
rules: [
...(currentConfiguration.module?.rules ?? []),
// Add more loaders here
],
},
};
});
remotion.config.ts
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.

When using bundle() and deploySite()

When using the Node.JS APIs - bundle() for SSR or deploySite() for Lambda, you also need to provide the Webpack override, since the Node.JS APIs do not read from the config file. We recommend you put the webpack override in a separate file so you can read it from both the command line and your Node.JS script.

src/webpack-override.ts
ts
import { WebpackOverrideFn } from "remotion";
 
export const webpackOverride: WebpackOverrideFn = (currentConfiguration) => {
return {
...currentConfiguration,
// Your override here
};
};
src/webpack-override.ts
ts
import { WebpackOverrideFn } from "remotion";
 
export const webpackOverride: WebpackOverrideFn = (currentConfiguration) => {
return {
...currentConfiguration,
// Your override here
};
};
remotion.config.ts
ts
import { Config } from "remotion";
import { webpackOverride } from "./src/webpack-override";
 
Config.Bundling.overrideWebpackConfig(webpackOverride);
remotion.config.ts
ts
import { Config } from "remotion";
import { webpackOverride } from "./src/webpack-override";
 
Config.Bundling.overrideWebpackConfig(webpackOverride);
my-script.js
ts
import { bundle } from "@remotion/bundler";
import { webpackOverride } from "./src/webpack-override";
 
await bundle({
entryPoint: require.resolve("./src/index.ts"),
webpackOverride,
});
my-script.js
ts
import { bundle } from "@remotion/bundler";
import { webpackOverride } from "./src/webpack-override";
 
await bundle({
entryPoint: require.resolve("./src/index.ts"),
webpackOverride,
});

Snippets

Enabling MDX support

  1. Install the following dependencies:
bash
npm i mdx-loader babel-loader @babel/preset-env @babel/preset-react
bash
npm i mdx-loader babel-loader @babel/preset-env @babel/preset-react
  1. Create a file with the Webpack override:
enable-mdx.ts
ts
export const enableMdx: WebpackOverrideFn = (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",
],
},
],
},
};
};
enable-mdx.ts
ts
export const enableMdx: WebpackOverrideFn = (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",
],
},
],
},
};
};
  1. Add it to the config file:
remotion.config.ts
ts
import { Config } from "remotion";
import { enableMdx } from "./src/enable-mdx";
 
Config.Bundling.overrideWebpackConfig(enableMdx);
remotion.config.ts
ts
import { Config } from "remotion";
import { enableMdx } from "./src/enable-mdx";
 
Config.Bundling.overrideWebpackConfig(enableMdx);
  1. Add it to your Node.JS API calls as well if necessary.

  2. 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

  1. Install the following dependencies:
bash
npm i sass sass-loader
bash
npm i sass sass-loader
  1. Declare an override function:
src/enable-sass.ts
ts
import { WebpackOverrideFn } from "remotion";
 
const enableSass: WebpackOverrideFn = (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 } },
],
},
],
},
};
};
src/enable-sass.ts
ts
import { WebpackOverrideFn } from "remotion";
 
const enableSass: WebpackOverrideFn = (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 } },
],
},
],
},
};
};
  1. Add the override function to your remotion.config.ts file:
remotion.config.ts
ts
import { Config } from "remotion";
import { enableSass } from "./src/enable-sass";
 
Config.Bundling.overrideWebpackConfig(enableSass);
remotion.config.ts
ts
import { Config } from "remotion";
import { enableSass } from "./src/enable-sass";
 
Config.Bundling.overrideWebpackConfig(enableSass);
  1. Add it to your Node.JS API calls as well if necessary.

  2. Restart the preview server.

Enable support for GLSL imports

  1. Install the following dependencies:
bash
npm i glsl-shader-loader glslify glslify-import-loader raw-roader
bash
npm i glsl-shader-loader glslify glslify-import-loader raw-roader
  1. Declare a webpack override:
src/enable.glsl.ts
ts
import { WebpackOverrideFn } from "remotion";
 
export const enableGlsl: WebpackOverrideFn = (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"],
},
],
},
};
};
src/enable.glsl.ts
ts
import { WebpackOverrideFn } from "remotion";
 
export const enableGlsl: WebpackOverrideFn = (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"],
},
],
},
};
};
remotion.config.ts
ts
import { Config } from "remotion";
import { enableGlsl } from "./src/enable-glsl";
 
Config.Bundling.overrideWebpackConfig(enableGlsl);
remotion.config.ts
ts
import { Config } from "remotion";
import { enableGlsl } from "./src/enable-glsl";
 
Config.Bundling.overrideWebpackConfig(enableGlsl);
  1. 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;
}
  1. Add it to your Node.JS API calls as well if necessary.

  2. Reset the webpack cache by deleting the node_modules/.cache folder.

  3. 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 - synchronous
ts
import { Config } from "remotion";
 
Config.Bundling.overrideWebpackConfig((conf) => {
return {
...conf,
experiments: {
syncWebAssembly: true,
},
};
});
remotion.config.ts - synchronous
ts
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 - asynchronous
ts
import { Config } from "remotion";
 
Config.Bundling.overrideWebpackConfig((conf) => {
return {
...conf,
experiments: {
asyncWebAssembly: true,
},
};
});
remotion.config.ts - asynchronous
ts
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.

Add the Webpack override to your Node.JS API calls as well if necessary.

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.

See also