Code Monkey home page Code Monkey logo

Comments (6)

ScriptedAlchemy avatar ScriptedAlchemy commented on May 16, 2024 7

Lol okay sorry.

Here we go

As long as you have async bootstrap import, or a parent import, you can use static import without a problem.

It's not "bad" but you will be loading more code upfront in order for that chunk to start.

I always say use dynamic import when possible because it's better for code splitting. We don't have to load as much code in the parent chunk.

Using static imports is sometimes necessary. React hooks for example. Those we can static import because it's hard not to.

But where async can be used, we want to use it. So that we are not creating giant amount s of remote code be downloaded because everything is going back to the top bootstrap import.

The bootstrap import itself is only in all my example because everything needs react to start. So there's not much else to go in the entry point other than importing react.

If you're entry-point contained no static import of a shared module, then you can code as normal. Just make sure to dynamic import the bootstrap file when you want the shared modules to start.

Is that a better explanation?

Many static imported federated modules would be bad practice- not problematic for webpack. Just not what we advise for heavy use (perf)

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 16, 2024 2

You need to have a dynamic import somewhere in the parent to leverage static imports. This works by hoisting additional chunks to the nearest parent async import. This is how we can provide them in a sync manner, by moving them somewhere that we already have a promise pausing execution. If you use a dynamic import for bootstrap.js, usually solves the issue.

from module-federation-examples.

matthewma7 avatar matthewma7 commented on May 16, 2024

Thank you for the answering. 🙂
Can I say, if handled with care, it is possible to use module federation with just static import like before?

I am not super clear that you said 'If you use a dynamic import for bootstrap.js, usually solves the issue'. The example is using dynamic import for the bootstrap.js but the React.lazy and Suspense is still needed in the case?

from module-federation-examples.

lzxb avatar lzxb commented on May 16, 2024

image

The route on the page is provided by other remote modules, so static import will be used. Now the project in the production environment will cause a lot of requests, and those unused modules will be requested. I don't know why

image

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 16, 2024

Static imports, used or not would be loaded since they are eager imports.

from module-federation-examples.

lzxb avatar lzxb commented on May 16, 2024

Oh, I see

from module-federation-examples.

Related Issues (20)

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.