From 7c08a98e78ccd7b4c482f3312bfcd5ecb035bb3f Mon Sep 17 00:00:00 2001 From: Alexandre Santos Date: Fri, 12 Mar 2021 17:52:01 +0000 Subject: [PATCH 1/5] feat(babel-plugin): add initial draft --- ...andling-react-remote-modules-with-babel.md | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 content/blog/handling-react-remote-modules-with-babel.md diff --git a/content/blog/handling-react-remote-modules-with-babel.md b/content/blog/handling-react-remote-modules-with-babel.md new file mode 100644 index 0000000..7e3705d --- /dev/null +++ b/content/blog/handling-react-remote-modules-with-babel.md @@ -0,0 +1,253 @@ +--- +title: Handling react remote modules with babel (wip) +description: 'WIP' +date: '2021-03-12' +published: false +--- + +As my friend and colleague David is sharing on his blogpost series, we're using Microfrontends to enable different products to be created under the same codebase. +This is an ongoing effort to give teams the capability to iterate faster, and have independent release cycles while sharing code and maintaining the User Experience. David is doing a great job documenting this whole process and architecture, and thus I'll not repeat myself here. + +As part of this initiative, we created a shared library (which works as any other MFE) and only contains the components that are shared across products. All of this lives on a single repo, and we're using Webpack's Module Federation to define this clear interface between products. + +Here's what we need to do when we load a component that belongs to the **shared** library. This is what we'll refer to as a "remote component" throughout the rest of the article. + +- Import it using the ES6 `import` function - `import('shared/components/Button')` +- Wraps it in a React.lazy `const Button = React.lazy(() => import('shared/components/Button'))` + +That would result in something like the following: + +```js +import React from "react"; + +const Button = React.lazy(() => import("shared/components/Button")); + +const HomePage = () => { + return