If the goal is only to share a component folder within different projects, creating a versioned library might feel like a hassle. This repository illustrates how to import a UI library into multiple apps from repository root.
A soft symlink won't duplicate the files in git (which is what we want).
- Create the symlink by running inside
./nextjs-symlink
folder the following command.
ln -s ../ui-lib ./components
- Set
symlinks: false
inside webpack configurationresolve
options. See nextjs.config for an example. - Import the
Button
component in code.
import { Button } from '../components/ui-lib'