-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Robert Austin edited this page Sep 21, 2021
·
4 revisions
Use the local components library when developing components instead of having to publish to NPM every time.
You have 2 ways to use the components library locally.
- Put the component library and Next.js site in sibling folders:
.
├── stackbit-components
└── nextjs-site
- edit the
nextjs-site/package.jsonand replace the package with a localpath
"@stackbit/components": "file:../stackbit-components/dist"- edit the
nextjs-site/next.config.jsto use alias. This fixes the symlink problem.
// next.config.js
module.exports = {
...
webpack: (config, { webpack, isServer }) => {
config.resolve.alias['react'] = path.resolve('./node_modules/react');
config.resolve.alias['react-dom'] = path.resolve('./node_modules/react');
return config;
},
...
};- Put the component library and Next.js site in sibling folders:
.
├── stackbit-components
└── nextjs-site
- Follow the steps above to import the component library into a Next.js site
- Run
npm run distinsidestackbit-components, this will build the component library and save the artifacts into thedistfolder - Run
npm linkinsidestackbit-components/dist - Run
npm link @stackbit/componentsinsidenextjs-site - Edit the webpack config in the Next.js site
next.config.jsto not follow symlinks:
// next.config.js
module.exports = {
...
webpack: (config) => {
config.resolve.symlinks = false;
return config;
},
...
};