Next JS micro front-end project

Overview

Next JS micro front-end project

As you know the micro front-end is a new and very popular pattern to develop big front-end projects.

If you want to use only React.js or maybe other frameworks, There are several easy ways to do that, but in Next JS it will need a complex setup to do that, but this repository will help you!

There are some packages and ways to create a micro front-end based Next JS project, but they have some issues with Next JS:

  • You can not create routes in your micro project

  • It may run various local hosts to manage your micro-projects

  • You can not use Next JS server-side features such as getServerSideProps

  • You can not create API routes in micro-projects

  • It can create performance issues

  • You may need to install any packages you need for every micro-projects

This repository has solved all these problems!

How to use this project?

You need to install yarn first if you don't have it you can install it using :

npm install yarn -g

Then you have to install nodemon:

yarn add nodemon -g

After that, you can clone (or download and unzip) the repository and then in the root folder run yarn

And now you're ready to start the project!

yarn dev


How to add and sync a micro project?

  1. Copy the initialMicroProject to the projects directory and rename it as you wish.

  2. Open the micro project, and then open the package.json.

  3. Rename your project "name" to what you desire, But it should start with @ and have a / in it for example: @main/test-micro-project

  4. In your micro-project you will no longer use pages to make a route, you will use routes instead.

  5. open RoutesInfo.js and you should address your micro project in the routePath section for example if your project folder name is test you should write: routePath: "../test/routes"

(You have to come one directory up using ../ and then write your project path.

  1. open the main folder in the projects folder, find getRoutes.js and open it

  2. first require your micro-project RoutesInfo.js file in that file for example :

const dashboardRoutes = require("../dashboard/RoutesInfo");

  1. In the SetRoute function add your file to the array like this :

dashboardRoutes().routeInfo.routePath

  1. We are done! now open your micro project and make your routes in the routes folder just like you do in Next JS.

But there is an important note :

You can not use your file in your micro-project like used to do.

You have to create another folder at the root of your micro-project (the name doesn't matter I will use pages for example)

You create a component in the pages folder in then you will import and use it in your routes like this :

import MainPage from "@main/test/pages/main/main";

@main/test is the name you chose in your micro-project package.json

That's it!

Now you can write your code (outside of the routes folder, in any other place).


How to use API routes?

just like you create normal pages, you should create a folder called api in routes folder

Then import your server-side code from another folder (like you do to create pages)

this is an example of how you can use it :

(this is in the routes folder)

import {RequestHandler} from "@main/dashboard/apis/testAPI/index";

  

export default function handler (req, res) {

RequestHandler(req, res);

}

How to use things like getServerSideProps ?

As you can see in example pages there are next server-side functions commented.

You should have another file to handle the functions.

This should be in your routes folder

export const getServerSideProps = async(ctx) => {

const props = SSR.functions.getServerSideProps(ctx);

return props;

}

and in another folder that you create your page you have to use this template :

{ return { props: {}, }; }; const getStaticPaths = async (ctx) => { return { paths: [ { params: {}, }, ], fallback: "blocking", }; }; export default function getSSRFunctions() { let SSRfunctions = { status: ServerSideFunctions, functions: { getServerSideProps: getServerSideProps, getStaticProps: getStaticProps, getStaticPaths:getStaticPaths }, }; return SSRfunctions; }">
const ServerSideFunctions = {

getServerSideProps: true,

getStaticProps: true,

getStaticPaths: true,

};

const getServerSideProps = async (ctx) => {

console.log("getServerSideProps");

return {

props: {

hello: "world",

},

};

};

const getStaticProps = async (ctx) => {

return {

props: {},

};

};

const getStaticPaths = async (ctx) => {

return {

paths: [

{

params: {},

},

],

fallback: "blocking",

};

};

export default function getSSRFunctions() {

let SSRfunctions = {

status: ServerSideFunctions,

functions: {

getServerSideProps: getServerSideProps,

getStaticProps: getStaticProps,

getStaticPaths:getStaticPaths

},

};

return SSRfunctions;

}

and import it in your route as you know :

import getSSRFunctions from "@main/test/pages/main/ServerSide";

That's it leave the routes folder and write your code in ServerSide.js (for e.g) file!

Using tests:

This repository uses cypress you can write tests in the cypress folder (root folder of the project)

these commands are defined to use :

yarn cypress:run-all-tests : run all tests in terminal

yarn cypress:run-test : run a single spec test file

cypress:run-project : --- not currently available to use ---


How to install a package?

To install a package that you can access in all of your micro-projects you should use the command in the root folder (not in your micro-project folder) :

yarn add package-name -W


example micro-projects :

there are some examples of micro-projects with :

Material UI and configuration,

socket.io,

Axios, SWR, ...


In the end, I want to mention a few things:

  • This project is a new project, and It's in the beginning stage of development, so it's not currently stable.
  • If I see that people like this project, and It's worth spending time, I will add some perfect features
  • You can contact me using: [email protected]
  • Please if you like this project, like and share the GitHub repository.

[To-do]:

  • Create an NPM package, so you can create a project or a micro project using a command like these:

    npx create-mf-next-app app-name

    and

    npx add-micro-project micro-project-name --template mui

  • improve the document and examples (maybe creating a website)

*Add a command-line tool with these features:

get all routes

detect duplicated routes paths

....

You might also like...

Demo project to deploy front- and backend together on heroku.

spring-boot-react-bundle This is a demo project that shows how it is possible to deploy a react frontend and a Spring Boot backend into a heroku dyno.

Jul 22, 2022

Next-multipart - Easy & Simple File Uploads for Next.js

Next-Multipart Next-multipart is a small utility library to ease the process of file uploads with Next.js. It uses formidable under the hood, but with

Nov 11, 2022

Find your duo - front/back/mobile

Find your duo - front/back/mobile

Sobre Este projeto é a trilha Ignite que engloba o projeto (backend, frontend e mobile) Find Your Duo . Aulas 01 - Configuração do ambiente 02 - Desen

Sep 19, 2022

E-commerce project using Next.js

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Jan 5, 2022

This is best boilerplate project using Next.js, Typescript, Redux, Styled-component.

GL-Next boilerplate Start your next Next project in seconds A highly scalable, offline-first foundation with the best DX and a focus on performance an

Sep 1, 2022

CoWIN Vaccination Tracker, Below is the PRODUCTION LINK this is updated at end of each day. To see any latest Updates, please check the documentation

CoWIN Vaccination Slots Checking App. CoWIN Vaccination Slots Checking App is a user-friendly website that allow users to find vaccine in nearby avail

Jan 28, 2022

The UI for staking NFTs on Solana. Cardinal staking UI can be treated as an admin interface for stake pools hosted by cardinal-staking as well as a barebones end-user staking UI

Cardinal Staking UI This repository hosts the UI inteface that powers https://stake.cardinal.so for staking NFTs on Solana. Use this repo to create an

Dec 24, 2022

🔄 Basic project to start studying React and Typescript. With it you can translate text to binary or morse language. This project addresses the creation of routes and components.

max-conversion Projeto criado para iniciar nos estudos de React e Typescript Basic project to gain knowledge in react Na plataforma é possível convert

Feb 12, 2022

This a todo list project that uses webpack. In this project you will find features like adding tasks, deleting tasks, maintaining localstorage, marking tasks completed and clearing all completed tasks.

webpack-Todo list This a todo list project that uses webpack. In this project you will find features like adding tasks, deleting tasks, maintaining lo

Jun 15, 2022
Owner
Amirreza
fullstack developer
Amirreza
Would You Rather App (Front End Developer Udacity Nanodegree)

Would You Rather App Table of Contents Overview Built with Install (How it works) Overview Would You Rather is the Second project with React Redux in

Ahmed Bayoumi 1 Apr 28, 2022
Bookstore CMS React Front-End to display a list of books, categorize it, add and remove books and update your reading progress

Bookstore REACT app to manage your books Build an app to display a list of books, categorize it, add and remove books and update your reading progress

Eapen Zacharias 3 Aug 19, 2022
Grid-tool - Small tool that allows you to integrate a predefined or generated grid into your front-end development environment.

Grid tool Small tool that allows you to integrate a predefined or generated grid into your front-end development environment. Tool installation includ

hmongouachon 2 Jan 4, 2022
Getir.com-react-tailwind - Getir.com anasayfa react + tailwind front-end

Getir.com React + Tailwind Front-end Bir gece uğraşı olarak getir.com'un anasayf

Tayfun Erbilen 102 Dec 17, 2022
A boilerplate for kickstarting my projects with Django backend and React front-end

Django-React-Boilerplate This is a boilerplate for kickstarting my projects with Django backend and React front-end. (AND, PostgreSQL) as the database

Mehedi Shafi 5 Apr 14, 2022
Front-end code for teia

Teia UI This repository is the frontend code of the open, community owned Tezos NFT Platform teia.art. Teia is a fork of the Tezos NFT platform Hic et

Teia Community 21 Dec 2, 2022
This is full stack todo Application which has front end and backend side on my own. So you can try this out. Build using

Full Stack Todo Application Hello Everyone... Here I am sharing some information about the TODO APP which I build using React, Redux, Material UI, Exp

Nayan Ingale 5 Nov 8, 2022
OpenMaze landing page front-end

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

OpenMaze 6 Dec 15, 2022
🔍 Remake of Reguleque's front-end, a search engine for government employees. Maintained by the América Transparente foundation.

regulf-react Frontend for Reguleque, a search engine for chilean public workers records' as obtained through transparency databases. Get started To ru

América Transparente 3 Dec 15, 2022
Fiz uma validação de senhas no Front-End usando RegEx!

Seja bem vindo a um dos meus #JokeCodes Nesse código vou te mostrar como fazer uma validação de senha no Front-End, com feedback na tela de login!, us

JOÃO PSTER 3 Oct 5, 2022