question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] What's the best practices of shared dependencies?

See original GitHub issue
  1. Include all dependencies in shared
const { dependencies } = require('./package.json');

{
  shared: {
    ...dependencies,
    react: {
      singleton: true,
      requiredVersion: dependencies['react'],
    },
    'react-dom': {
      singleton: true,
      requiredVersion: dependencies['react-dom'],
    },
  },
}

This seems will end up with too many chunks, feels a bit overwhelming as it leads to a lot more requests.

  1. Only include necessary ones, like those need to be singleton and those large dependencies
{
  shared: {
    component-library: {
      requiredVersion: '^x.x.x',
    },
    '@apollo/client': {
      requiredVersion: '^x.x.x',
    },
    react: {
      singleton: true,
      requiredVersion: dependencies['react'],
    },
    'react-dom': {
      singleton: true,
      requiredVersion: dependencies['react-dom'],
    },
  },
}

Then we would need to carefully sync the required versions so that each federated module compatible with each other

  1. Only include those need to be singleton
{
    react: {
      singleton: true,
      requiredVersion: dependencies['react'],
    },
    'react-dom': {
      singleton: true,
      requiredVersion: dependencies['react-dom'],
    },
  },
}

I understand it is different case by case, but would be nice to see what other people think 😃

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ScriptedAlchemycommented, Aug 30, 2022

Consider booking a call. This is tricky to document.

Free of charge. I’ll record the session and post it back here for others.

Easier to talk than write. I cannot read very well so it’s difficult to keep track of the words.

https://calendly.com/d/dwg-3cb-75w/private-session

1reaction
icy0307commented, Aug 30, 2022

Just to be clear, For an comprehensive example of an react-redux app, instead of the below code, https://github.com/module-federation/module-federation-examples/blob/5142c518b29e6ec94216e3c895d448cff3e2ef10/comprehensive-demo/app-01/webpack.config.js#L61-L75 the correct way to do this is?

const deps = require('./package.json').dependencies;
...
 shared: { 
   'core-js/': { 
     requiredVersion: deps.core-js,
   }, 
   'lodash-es/': { 
     requiredVersion: deps.lodash-es,
   }, 
   '@reduxjs/toolkit': { 
     singleton: true, 
   }, 
   'react-dom': { 
     singleton: true, 
   }, 
   react: { 
     singleton: true, 
   }, 
   i18next: { 
     singleton: true, 
   }, 
  '@mui/material/': {
     requiredVersion: deps.@mui/material,
    }
 },
  1. What if I split chunk in my app(host app), would core-js/ bundle the polyfill that not in host app initial chunk?
  2. Sometimes, host app and remote apps are not in the same repo. The remote apps may be used in different host apps. If host app1 wanna share the same store, and host app2 need store isolation, how to handle this situation? @ScriptedAlchemy
Read more comments on GitHub >

github_iconTop Results From Across the Web

A question about best practice on multiple dependency jar ...
A good practice I recommend is to use enforcer Plugin with dependency convergence goal. This way you are forced to decide which version...
Read more >
Intro to Microservices, Part 4: Dependencies and Data ...
Learn the basics of dependency management and data sharing for ... We will now study how some of these questions are answered in...
Read more >
Dependencies in Project Management
The four internal dependencies are based on logic, resources, preferences and best practices, and cross-team dependencies.
Read more >
For nodejs what are best design practices for native ...
Prompted by rsms I'd like to share the architecture I'm going with now originally answered/shared here on stackoverflow. What's the best way ...
Read more >
AWS CloudFormation best practices
Use best practices to help you use AWS CloudFormation more effectively and securely. ... Use cross-stack references to export shared resources.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found