Sharing Code Between NextJS Applications

Sharing Code Between NextJS Applications

By setting up a simple TypeScript monorepo.

Sharing code between NextJS projects can be easy. With yarn workspaces you can have multiple applications in a single repository — a monorepo — and use the next-transpile-modules plugin to allowing the importing of code from one into another.

See the example repo here.

Image for post

I had a NextJS application which had become quite large, to the point where it made more sense to start migrating some of it to a new, separate NextJS application. But some code would be needed in both the original application and the new one.

The code I wanted to share was very simple — not worthy of its own repository, not worthy of building/publishing it and including it as an external dependency. I just wanted to import the code from one application into another.

To achieve this, I built a simple monorepo — one repository containing both of my NextJS applications — which supported code sharing between the applications. This was made easy thanks to yarn workspaces and the next-transpile-modules plugin.

typescr react javascript nextjs

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

Top VSCode Extensions for React, React Native, JavaScript and Productivity

Bunch of VSCode Extensions that improve quality of your coding time no matter what stack you are using. In this post, you'll see Top VSCode Extensions for React, React Native, JavaScript and Productivity

Qual a relação entre Java e JavaScript, C e C++, React e React Native

Qual a relação entre Java e JavaScript, C e C++, React e React Native

Routing in React without React-Router

I have been using React JS in my projects for quite some time now and am used to managing routing in my app using the react-router package. I have always been keen on having as little dependencies in my apps as possible, so, I always felt perturbed by the use of this particular package in simpler apps which did not have complex routes.