Skip to content

Commit

Permalink
docs: Added a getting started template
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed May 7, 2024
1 parent 1125704 commit e8f6102
Show file tree
Hide file tree
Showing 53 changed files with 1,209 additions and 68 deletions.
53 changes: 29 additions & 24 deletions docs/getting-started/create-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ label: Create an host app

# Create an host application

!!!warning Use an existing template

We highly recommend going through the entire getting started guide. However, if you prefer to scaffold the application we'll be building, a template is available.

+++ pnpm
```bash
pnpm dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ yarn
```bash
yarn dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ npm
```bash
npx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++
!!!

Let's begin by creating the application that will serve as the entry point for our federated application and host the application modules.

## Install the packages
Expand All @@ -13,17 +32,17 @@ Create a new application (we'll refer to ours as `host`), then open a terminal a

+++ pnpm
```bash
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
pnpm add -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
pnpm add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ yarn
```bash
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
yarn add -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
yarn add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ npm
```bash
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
npm install -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss typescript @types/react @types/react-dom
npm install @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++
Expand Down Expand Up @@ -98,7 +117,7 @@ const runtime = new FireflyRuntime({
});

// Register the remote module.
await registerRemoteModules(Remotes, runtime;
await registerRemoteModules(Remotes, runtime);

const root = createRoot(document.getElementById("root")!);

Expand Down Expand Up @@ -253,7 +272,7 @@ Finally, update the bootstrapping code to [register](../reference/registration/r

```tsx !#17 host/src/bootstrap.tsx
import { createRoot } from "react-dom/client";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerLocalModules, registerRemoteModules, type RemoteDefinition } from "@squide/firefly";
import { App } from "./App.tsx";
import { registerHost } from "./register.tsx";

Expand Down Expand Up @@ -370,7 +389,7 @@ export const swcConfig = defineDevConfig(targets);

Then, open the `webpack.dev.js` file and use the [defineDevHostConfig](/reference/webpack/defineDevHostConfig.md) function to configure webpack:

```js !#13-20 host/webpack.dev.js
```js !#13 host/webpack.dev.js
// @ts-check

import { defineDevHostConfig } from "@squide/firefly-webpack-configs";
Expand All @@ -379,18 +398,11 @@ import { swcConfig } from "./swc.dev.js";
/**
* @typedef {import("@squide/firefly-webpack-configs").RemoteDefinition[]}
*/
const Remotes: RemoteDefinition[] = [
const Remotes = [
{ name: "remote1", url: "http://localhost:8081" }
];

export default defineDevHostConfig(swcConfig, 8080, Remotes, {
sharedDependencies: {
"@sample/shared": {
singleton: true,
eager: true
}
}
});
export default defineDevHostConfig(swcConfig, 8080, Remotes);
```

> If you are having issues with the wepack configuration that are not related to module federation, refer to the [@workleap/webpack-configs](https://gsoft-inc.github.io/wl-web-configs/webpack/configure-dev/) documentation.
Expand All @@ -411,7 +423,7 @@ export const swcConfig = defineBuildConfig(targets);

Then, open the `webpack.build.js` file and use the [defineBuildHostConfig](/reference/webpack/defineBuildHostConfig.md) function to configure webpack:

```js !#13-20 host/webpack.build.js
```js !#13 host/webpack.build.js
// @ts-check

import { defineBuildHostConfig } from "@squide/firefly-webpack-configs";
Expand All @@ -424,14 +436,7 @@ const Remotes = [
{ name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(swcConfig, Remotes, {
sharedDependencies: {
"@sample/shared": {
singleton: true,
eager: true
}
}
});
export default defineBuildHostConfig(swcConfig, Remotes);
```

> If you are having issues with the wepack configuration that are not related to module federation, refer to the [@workleap/webpack-configs](https://gsoft-inc.github.io/wl-web-configs/webpack/configure-build/) documentation.
Expand Down
34 changes: 27 additions & 7 deletions docs/getting-started/create-local-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ order: 80

# Create a local module

!!!warning Use an existing template

We highly recommend going through the entire getting started guide. However, if you prefer to scaffold the application we'll be building, a template is available.

+++ pnpm
```bash
pnpm dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ yarn
```bash
yarn dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ npm
```bash
npx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++
!!!

Local modules are regular modules that are part of the **host application build**. They are independent modules that expose a `registration` function to the host application's bootstrapping code. A local module can be a standalone package, a sibling project (in a monorepo setup), or even a local folder within the host application.

Local modules have many uses but are especially useful when **migrating** from a **monolithic application** to a distributed application or when **launching** a **new product** with an unrefined business domain.
Expand Down Expand Up @@ -69,7 +88,7 @@ Finally, configure the package to be shareable by adding the `name`, `version`,

```json local-module/package.json
{
"name": "@sample/local-module",
"name": "@getting-started/local-module",
"version": "0.0.1",
"exports": {
".": {
Expand Down Expand Up @@ -114,23 +133,24 @@ export function Page() {

## Register the local module

Go back to the `host` application and add a dependency to the `@sample/local-module` package in the host application `package.json` file:
Go back to the `host` application and add a dependency to the `@getting-started/local-module` package in the host application `package.json` file:

```json host/package.json
{
"dependencies": {
"@sample/local-module": "0.0.1"
"@getting-started/local-module": "0.0.1"
}
}
```

Then, register the local module with the [registerLocalModules](/reference/registration/registerLocalModules.md) function:

```tsx !#3,20 host/src/bootstrap.tsx
```tsx !#3,21 host/src/bootstrap.tsx
import { createRoot } from "react-dom/client";
import { ConsoleLogger, RuntimeContext, FireflyRuntime, registerRemoteModules, registerLocalModules, type RemoteDefinition } from "@squide/firefly";
import { register as registerMyLocalModule } from "@sample/local-module";
import { register as registerMyLocalModule } from "@getting-started/local-module";
import { App } from "./App.tsx";
import { registerHost } from "./register.tsx";

// Define the remote modules.
const Remotes: RemoteDefinition[] = [
Expand All @@ -146,9 +166,9 @@ const runtime = new FireflyRuntime({
await registerRemoteModules(Remotes, runtime);

// Register the local module.
registerLocalModules([registerMyLocalModule], runtime);
registerLocalModules([registerHost, registerMyLocalModule], runtime);

const root = createRoot(document.getElementById("root"));
const root = createRoot(document.getElementById("root")!);

root.render(
<RuntimeContext.Provider value={runtime}>
Expand Down
45 changes: 26 additions & 19 deletions docs/getting-started/create-remote-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ order: 90

# Create a remote module

!!!warning Use an existing template

We highly recommend going through the entire getting started guide. However, if you prefer to scaffold the application we'll be building, a template is available.

+++ pnpm
```bash
pnpm dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ yarn
```bash
yarn dlx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++ npm
```bash
npx degit https://github.com/gsoft-inc/wl-squide/templates/getting-started
```
+++
!!!

Remote modules are modules that are not included in the host application build but are instead **loaded at runtime** from a remote server. They provide a way for teams to be **fully autonomous** by **independently deploying** their modules without relying on the other parts of the application.

Let's add our first remote module!
Expand All @@ -14,17 +33,17 @@ Create a new application (we'll refer to ours as `remote-module`), then open a t

+++ pnpm
```bash
pnpm add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
pnpm add -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
pnpm add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ yarn
```bash
yarn add -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
yarn add -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
yarn add @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++ npm
```bash
npm install -D @workleap/webpack-configs @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
npm install -D @workleap/swc-configs @workleap/browserslist-config @squide/firefly-webpack-configs webpack webpack-dev-server webpack-cli @swc/core @swc/helpers browserslist postcss @types/react @types/react-dom
npm install @squide/firefly react react-dom react-router-dom react-error-boundary
```
+++
Expand Down Expand Up @@ -111,19 +130,13 @@ export const swcConfig = defineDevConfig(targets);

Then, open the `webpack.dev.js` file and use the [defineDevRemoteModuleConfig](/reference/webpack/defineDevRemoteModuleConfig.md) function to configure webpack:

```js !#6-12 remote-module/webpack.dev.js
```js !#6 remote-module/webpack.dev.js
// @ts-check

import { defineDevRemoteModuleConfig } from "@squide/firefly-webpack-configs";
import { swcConfig } from "./swc.dev.js";

export default defineDevRemoteModuleConfig(swcConfig, "remote1", 8081, {
sharedDependencies: {
"@sample/shared": {
singleton: true
}
}
});
export default defineDevRemoteModuleConfig(swcConfig, "remote1", 8081);
```

> If you are having issues with the wepack configuration that are not related to module federation, refer to the [@workleap/webpack-configs](https://gsoft-inc.github.io/wl-web-configs/webpack/configure-dev/) documentation.
Expand All @@ -144,19 +157,13 @@ export const swcConfig = defineBuildConfig(targets);

Then, open the `webpack.build.js` file and use the [defineBuildRemoteModuleConfig](/reference/webpack/defineBuildRemoteModuleConfig.md) function to configure webpack:

```js !#6-12 remote-module/webpack.build.js
```js !#6 remote-module/webpack.build.js
// @ts-check

import { defineBuildRemoteModuleConfig } from "@squide/firefly-webpack-configs";
import { swcConfig } from "./swc.build.js";

export default defineBuildRemoteModuleConfig(swcConfig, "remote1", {
sharedDependencies: {
"@sample/shared": {
singleton: true
}
}
});
export default defineBuildRemoteModuleConfig(swcConfig, "remote1");
```

> If you are having issues with the wepack configuration that are not related to module federation, refer to the [@workleap/webpack-configs](https://gsoft-inc.github.io/wl-web-configs/webpack/configure-build/) documentation.
Expand Down
Loading

0 comments on commit e8f6102

Please sign in to comment.