Skip to content

remove import bootstrap from apps that can support it #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020

Conversation

ScriptedAlchemy
Copy link
Member

Here a few updates what happened on the dev-1 branch:

Overridables (shared) to no longer require wrapping in import(). So no unneccessary import("./bootstrap") in your app code because of container-related plugins. (Note: remote modules still require import(), that won't change.)
Persistent caching with container-related plugins is now possible.
Container-related plugins are now exposed under require("webpack").container.XXXPlugin and have typings
ModuleFederationPlugin doesn't create a container when no exposes are specified
Improved schema validation

after testing this out, it's important to note that if you consume exposes inside a remote app, you will need to use a dynamic import somewhere, perhaps not on the root of the app @sokra ?

import LocalButton from "./Button";
import React from "react";

const App = () => (
  <div>
    <h1>Basic Host-Remote</h1>
    <h2>App 2</h2>
    <LocalButton />
  </div>
);

export default App;

with

import React from "react";

const Button = () => <button>App 2 Button</button>;

export default Button;

and a webapck config that has this.

new ModuleFederationPlugin({
      name: "app2",
      library: { type: "var", name: "app2" },
      filename: "remoteEntry.js",
      exposes: {
        Button: "./src/Button",
      },
      shared: ["react", "react-dom"],
    }),

Will require you to either use import(bootstrap.js) in the REMOTE's entrypoint in order for it to work.

OR

you can dynamically import the file itself. Either way, you need a dynamic import on the remote in the execution chain - a promise must exist somewhere to hoist imports up.

import React, {Suspense} from "react";
const LocalButton = React.lazy(()=>import('./Button'));

const App = () => (
  <div>
    <h1>Basic Host-Remote</h1>
    <h2>App 2</h2>
    <Suspense fallback={null}>
      <LocalButton />
    </Suspense>
  </div>
);

export default App;

import(bootstrap.js) will allow you to do this

import LocalButton from "./Button";

Otherwise, if you don't want to have a dynamic import in entrypoint, you can use it like this
const LocalButton = React.lazy(()=>import('./Button'));

@ScriptedAlchemy ScriptedAlchemy merged commit 178fa0f into master Apr 30, 2020
newvladimirov pushed a commit to newvladimirov/module-federation-examples that referenced this pull request Jul 17, 2020
…basic-bootstrap

remove import bootstrap from apps that can support it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant