Next.js shared repository component
These days I’m building several next.js apps and want to share some libraries. In the beginning plain js file without compile just work well. But when it comes to jsx component element with sass component-level module, next.js start to fail.
After several tries, I found a solution:
- Create shared package somewhere
- Use
yarn link
to link shared library - Use
next-transpile-module
to transpile library - Tada!
More detail
1 | # Shared repo |
Then edit next.config.js
1 | const withTM = require('next-transpile-modules')(['shared']) |
You can now use
1 | import awesome_component from 'shared' |
in your repository!
Hope this helps you! :)