Skip to main content

Build a library providing bricks as a npm package

This tutorial explains how to build a library that provides bricks, coded or drawn, to be imported in another Olympe project. Specifically, Olympe projects and the related tools rely on npm to manage dependencies. In that logic, building a library with Olympe means building a npm package.

Create an Olympe project and build it as a library

To follow this tutorial, you need to set up an Olympe project using the Yeoman project generator. When asked for, answer that your project is intended to be a library (and not that it will run applications). Then, build to your convenience a set of coded or drawn bricks as described in previous tutorials:


The project that you want to provide as a npm package and all the bricks that you want to use in another project must be made publicly visible in DRAW through their respective Spec & Doc editors. That is, go to your project's root in DRAW, click on the Spec & Doc tab, and check on the Public box in the visibility section. Repeat that operation for any brick you want to make public.

To build your project as a npm package, run

npm run build

The script will ask you if you want to snapshot the project first. If you have done any work in DRAW since you last snapshot your project, you must snapshot it again before continuing. Otherwise, the package will not provide the latest version of the data cloud initialisation files. Then Webpack builds the project as a npm package in the dist/ directory of your project. This package provides both the project's data cloud initialisation JSON files and the bricks source code. It is not yet accessible to anyone. See below to learn how to make a package available.

Package content


Webpack creates automatically a package.json for the package. You may change it at your convenience. However, it must always contain the field dcInitConfig. If this field misses, the Olympe dev-tools will not identify that the package provides data cloud initialisation files and the data cloud initialisation will fail.

Default value:

dcInitConfig: import/dcInitConfig.json

dcInitConfig.json is the data cloud initialisation configuration file, i.e. the list of modules to load during the data cloud initialisation step.

Make the package available

The package is built and ready in the dist/ directory of your project, but not yet accessible to anyone. You can navigate to the dist/ directory and either publish the package on a npm registry with npm publish to make it publicly available or link the package on your system to use it in another of your projects with npm link. If your intention is to develop a library in parallel to using it in another project, you definitely want learn how to dynamically link a package to your global npm installation.

After you have built a package, navigate to the dist directory of that project. There, run

npm link

To check whether this package was correctly installed globally to the system, run from anywhere

npm list -g

or even more explicitly

npm list -g string-utils

The output should show a line with your package's name

├── <your-package-name>@0.1.0 -> /Users/olympe-dev/tutorials/<your-package-name>/dist

Your mileage may vary, but make sure the link points to the dist directory of your project, in which the package was built, and not to the project's root repository.