Setting your workspace
This guide explains how to set up your environment using the ragu-cli
tool.
It includes installing the CLI, creating an initial workspace and simple micro-frontend.
Also, this guide explains how to run the micro-frontend locally.
#
Start a Node project- I already have a node project
- Tell me how to start one
If you don't have a project yet 1
open your terminal and follow the steps bellow:
2
Create a directory.
3
Open the directory you have created.
4
Create a node project
- Yarn
- NPM
#
Install the ragu-cliYou use the ragu-cli to build micro-frontends, develop and preview your micro-frontend.
To install the ragu-cli
, execute the following command at the terminal:
- Yarn
- NPM
#
WebpackRagu abstracts part of webpack configuration. It means that you should not worry about having a webpack config file if you don't use any special loader. However, webpack must be installed manually to make sure Ragu is using the same webpack version of your project. You can skip this step if you already have webpack installed.
- Yarn
- NPM
#
AdaptersRagu is technology-agnostic. That means it can be used with any javascript framework. However,
ragu-cli
needs to know how to build your project. The adapters are how you can tell Ragu how to build the
micro-frontend. For this example we will use the adapter for vanilla (a.k.a pure javascript) micro-frontends.
- Yarn
- NPM
note
All the examples bellow are about exporting a javascript pure micro-frontend. There is even a smooth way to work with your favorite framework. Check React's and Vue's documentation for more info.
info
Does not install the simple adapter if you will use a framework. Install the framework adapter instead.
#
Creating a simple componentOpen your favorite text editor and create a javascript file for out micro-frontend:
note
A Ragu micro-frontend is always a file that exports a default
function.
#
Run the applicationThe Ragu includes a server, so that you can build and serve your app locally.
Run the following command to start the development server:
- Yarn
- NPM
The output should be like this:
Now you can use your micro-frontend wherever you want even here!
Your local micro-frontend
info
Try to change the micro-frontend! You will see that changes will be reflected here!
Code Example
The code of the examples above can be found here.
#
Previewing your micro-frontendTo preview your micro-frontend you just need to open the preview route that is printed at the terminal when you start the development server. Preview has hot-reload - changes are automatically updated.
The default micro-frontend route is http://localhost:3100/preview
#
Check all available commands and optionsIf you are having troubles to remember any ragu-cli
commands or options you can use the --help
flag.
- Yarn
- NPM
You can combine a command
with the --help
flag to list all available options for that command. Example:
- Yarn
- NPM