Skip to main content

Getting Started

Prerequisites

Before creating your first component, make sure your workstation meets the CLI installation requirements. If you followed the Quick-Start Tutorial you can skip this.

First create the component directory:

$ oc init hello-world

The above command will create the hello-world directory.

It is also possible to set template type during the initialisation as an additional init parameter:

$ oc init hello-world oc-template-es6

By default this parameter is set to oc-template-es6 (modern ES6 templates). Legacy templates like oc-template-handlebars are still supported for backwards compatibility.

Component structure

The basic component directory is composed by the following files:

├── hello-world/
├── package.json
├── src/view.ts
├── src/server.ts
├── public/
├── logo.png
  • package.json contains the component definition, dependencies, and more
  • view.ts is a template containing the markup
  • server.ts is an optional file, needed when the component has some logic

Additionally the component can have static contents such as images, js, and files that will be referenced in the html markup and any other files that will be useful for the development such as tests, docs, etc.

Structure of the package

The basic package file package.json looks as follows:

{
"name": "base-component-es6",
"description": "",
"version": "1.0.0",
"oc": {
"files": {
"data": "server.js",
"static": ["img"],
"template": {
"src": "src/view.ts",
"type": "oc-template-es6"
}
},
"parameters": {
"name": {
"default": "Jane Doe",
"description": "Your name",
"example": "Jane Doe",
"mandatory": false,
"type": "string"
}
}
},
"devDependencies": {
"oc-template-handlebars-compiler": "6.0.8"
}
}

Complete list of package.json parameters

Template

The template represents view layer of the component. OC supports modern ES6 templates by default, along with React, Vue, Svelte, and other javascript UI frameworks. Legacy templates like Handlebars and Jade are still supported for backwards compatibility.

Initialisation produces a basic hello-world example.

Basic server

Server is the entity that produces the view-model to compile the view. It is necessary when component template has logic, including consuming services. The basic version of server.js after initialization looks as follows:

export const data = (context, callback) => {
const { name } = context.params;
const { staticPath } = context;

callback(null, {
name,
staticPath,
});
};

Advanced server.js operations.

Editing, debugging, testing

You may want to start a local test registry using a components' folder as a library with a watcher. This will allow to consume and debug it:

$ oc dev . 3030

Then you may want to create a blank html page to start playing with it and see how it looks:

<html>
<body>
<oc-component href="http://localhost:3030/hello-world">
Optionally, some failover text here
</oc-component>
<script src="http://localhost:3030/oc-client/client.js"></script>
</body>
</html>

Or, just use the preview function:

$ oc preview http://localhost:3030/hello-world

That's it. As soon as you make changes on the component, you will be able to refresh this page and see how it looks.

When to Use Components

OpenComponents are ideal for:

  • Shared UI elements across multiple applications (headers, footers, navigation)
  • Team independence where different teams own different parts of the UI
  • Gradual migration from monolithic to micro frontend architecture
  • A/B testing individual components without affecting the entire application
  • Third-party integrations that need to be embedded in multiple sites

Example Repositories

Explore these example repositories to see OpenComponents in action:

Troubleshooting Common Issues

  • For installation problems, component creation errors, or dev-server hiccups, refer to the in-depth CLI guide which contains up-to-date solutions.

Next Steps

Once you've created your first component:

  1. Learn the CLI - Master all available commands
  2. Understand package.json structure - Configure your component properly
  3. Add server-side logic - Make your component dynamic
  4. Publish to a registry - Share your component
  5. Explore client-side operations - Advanced browser integration

For a complete hands-on tutorial, see our Quick Start Tutorial.