Guide

Component packages

A package can ship idlip components for other apps. It ships them as source, and the Vite plugin of the app compiles them together with the app's own files. A package ships no compiled output.

#Set up package.json

json
{
  "name": "@acme/ui",
  "version": "1.0.0",
  "type": "module",
  "idlip": { "version": 1, "dir": "src" },
  "exports": {
    "./*.tsx": "./src/*.tsx"
  },
  "files": ["src"],
  "sideEffects": ["**/*.css"],
  "peerDependencies": {
    "idlip": "^0.1.0"
  }
}

The app adds the package to its dependencies or devDependencies, and imports from it like any module:

tsx
import { For } from 'idlip';
import Counter from '@acme/ui/counter.tsx';

<For each={items} key={(item) => item.id}>
  {(item) => <Counter label={item.label} start={item.start} />}
</For>;

A package component has its own state, works as a child of the app's components and inside <For>, and resumes like an app component.

#How the plugin finds packages

When vite starts, the plugin reads the package.json of the app. For each entry of its dependencies and devDependencies that has an idlip field, it:

Only direct dependencies count. A package that uses components of another package needs that package in the app's dependencies as well. A linked package, such as one of a pnpm workspace, is read at its real folder, and vite dev serves and watches it even outside the project.

The modules option is for the app's own files and does not list packages.

#Names

A module of a package is named by the package and the path in it: src/button.tsx of @acme/ui is @acme/ui/src/button.tsx. The name is the same wherever the package is installed. The built chunk files carry the package name before the file name (@acme/ui is acme-ui), such as acme-ui.button.handler.press-<hash>.js, so two packages that both have a button.tsx do not collide. Two packages whose names give the same chunk name, such as @a/b-c and @a-b/c, stop vite at startup. The chunk files of the app's own files keep their names.

#Styles

A component imports its stylesheet and CSS Modules as an app component does:

tsx
import './counter.css';
import styles from './counter.module.css';

The page links the stylesheets of every component it can render, packages included. See Styles. A stylesheet that a package imports from a file under its source folder is linked even when the package is installed in node_modules. A stylesheet that a plain .ts module of a package imports is linked as well.

#Limits