The Framer plugin uses tsup for bundling. The configuration is specifically tuned to handle compatibility issues between @react-three/fiber dependencies (like react-reconciler and scheduler) and Framer's production React environment.
Key configuration behaviors:
- Platform & Format: Targets
browser and outputs esm. - Minification:
minify is set to false because minifying the build causes errors in react-reconciler within Framer. - External Dependencies:
react and framer are marked as external because Framer's canvas sandbox provides them via import maps. All other dependencies, including three, @react-three/fiber, and react-reconciler, must be bundled using noExternal to avoid resolution errors in the sandbox. - Environment:
process.env.NODE_ENV is forced to 'production'. - Plugins: Uses a custom
glslLoader for shader files and a reconcilerProdPlugin to wrap CommonJS versions of react-reconciler and scheduler into eager ESM modules to prevent runtime crashes.
export default defineConfig(async (options) => {
// ... configuration logic
return {
entry: await globby([`${basePath}/**/*.(t|j)s*`, `!${basePath}/**/*.d.ts`]),
platform: 'browser',
format: ['esm'],
dts: {
entry: 'src/index.ts',
},
minify: false,
clean: true,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
external: ['react', 'framer'],
noExternal: ['three', '@react-three/fiber', 'react-reconciler'],
esbuildPlugins: [glslLoader, reconcilerProdPlugin, commonjsPlugin()],
// ...
}
})