Code Monkey home page Code Monkey logo

nx-14-mfe's Introduction

NX 14 MFE

Example build orchestration using multiple nx 14 repos, docker, and netlify.

MFE structure

haightfillmore/
├─ apps/
│  ├─ cart/ * mysite.com/cart
│  ├─ catalog/ * mysite.com/catalog
│  ├─ shell/
somamission/
├─ apps/
│  ├─ about/ * mysite.com/about
│  ├─ shell/ * mysite.com/
Dockerfile

Manually upload Nx output to Netlify

cd somamission
nx build about --configuration=production
cd dist/apps/about/
open .
open https://app.netlify.com/drop
# drag and drop files
# store "Site ID" from: https://app.netlify.com/sites/my-deployed-site/settings/general

Deploy using docker

Create volumes for quicker builds

docker volume create mfe-npm-cache
docker volume create mfe-yarn-cache

Modify orchestration environment variables

touch .env.local
# copy contents of sample-env.local .env.local to and modify values
docker build --tag nx-builder .
docker run --env-file .env.local -v mfe-npm-cache:/tmp/npm-cache -v mfe-yarn-cache:/tmp/yarn-cache --rm nx-builder

(Optional) Deploying other apps

  1. Manually upload Nx output to Netlify
  2. Update .env.local
# ie:
# modify .env.local to deploy another monorepo app, ie: catalog
# DEPLOY_APP=haightfillmore
# DEPLOY_ROUTE=catalog
# CATALOG_SITE_ID=my-site-id
  1. Deploy using docker

Modify Remotes

// somamission/apps/shell/webpack.prod.config.js
  remotes: [
    [
      'about',
      'https//my-netlify-site.netlify.app/remoteEntry.mjs',
    ],
    // [
    //   'catalog',
    //   'https://my-netlify-site.netlify.app/remoteEntry.mjs',
    // ],
  ],

Modify Shell RouterModule

    RouterModule.forRoot(
      [
        {
          path: 'about',
          loadChildren: () =>
            import('about/Module').then((m) => m.RemoteEntryModule),
        },
        // {
        //   path: 'catalog',
        //   loadChildren: () =>
        //     import('catalog/Module').then((m) => m.RemoteEntryModule),
        // },
      ],

Build and Serve 🍦

cd somamission
nx serve shell --configuration=production --open

# or deploy
nx deploy shell
nx build shell --configuration=production

nx-14-mfe's People

Contributors

niculistana avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.