@digdir/designsystemet

中文文档
1.24.0发布于 2026/11/09MITTypeScriptES Module构建来源已验证近 30 天下载 1.5万

CLI for Designsystemet

原始使用文档

@digdir/designsystemet

CLI and tooling for Designsystemet

Use --help for available commands and options

Read the Designsystemet README to get started.

Usage

Use npx @digdir/designsystemet to create CSS for use with Designsystemet, based on a config file. It can also create type declarations and design tokens.

This allows you to define themes including custom colors, font-family, and border-radius. We recommend using the Designsystemet theme builder for generating a valid config.

OptionDescription
-c, --config <path>Path to config file (auto-detects designsystemet.config.json or designsystemet.config.jsonc)
--dryDry run - no files will be written
--verboseEnable verbose output
--skip-checkSkip migration check
-y, --yesSkip user prompts

⚠️ DEPRECATED ⚠️
The tokens create and tokens build commands are deprecated and will be removed in a future release. Use designsystemet with a config file instead.

Update tokens and CSS

Whenever a new version of the CLI is released, or you have done changes, re-run npx @digdir/designsystemet. Set cleanDir: true on an output to delete the files in its directory before creating new ones, which removes any deprecated or unneeded files. It is false by default. Directories inside a cleaned directory that are built from (tokensDir), or that belong to an output with cleanDir: false, are kept. Before deleting anything, the CLI stops with an error if a directory it would clean contains the config file, is one of those directories, is a symlink, or has a symlink on the way to one of them or to another output. Symlinks are deleted, never followed.

⚠️ WARNING ⚠️
The design tokens created by this tool are considered an implementation detail, and are subject to change at any time without being considered a breaking change. Make your customisations through the config where you can. You can edit the design tokens directly to change what the config doesn't support yet, see Sync Design Tokens with Tokens Studio, but you do so at your own risk: your edits may need to be redone or adjusted when you upgrade.

The CSS files created by this tool are considered build artifacts. They should not be edited directly. While the CSS will not change unexpectedly, new variables may be added at any time.

Therefore, it is necessary to routinely re-run this command when upgrading the libraries. Creating the design tokens again replaces any direct edits to them, and creating the CSS again replaces any direct edits to it.

Using a config file

The CLI will auto-detect a designsystemet.config.json or designsystemet.config.jsonc file in the current directory. You can also use the --config <path> option to supply a different config name and location.

Both .json and .jsonc files may contain comments and trailing commas (JSONC).

To get started, use this template for a designsystemet.config.json file:

{
  "$schema": "node_modules/@digdir/designsystemet/dist/config.schema.json",
}

In editors which support JSON Schema, the $schema will then give you editor hints for the structure of the file.

Minimal config example

{
  "$schema": "./node_modules/@digdir/designsystemet/dist/config.schema.json",
  "themes": {
    "theme": {
      "colors": {
        "accent": "#1E98F5",
        "neutral": "#1E2B3C",
      },
      "borderRadius": 4
    }
  }
}

To generate the CSS, you would then run:

npx @digdir/designsystemet

This creates CSS in designsystemet, relative to the config file, directly from the themes. Add "types" to output to also create type declarations, and "design-tokens" to also save the design tokens.

Output

Use output to choose what is created and where. Each item is either an output type ("design-tokens", "css" or "types") using its default settings, or an object:

{
  "output": [
    // defaults: dir "designsystemet/design-tokens", cleanDir false
    { "type": "design-tokens", "dir": "../path/to/design-tokens" },
    // defaults: dir "designsystemet", tokensDir from the design-tokens output, cleanDir false, tailwind false
    { "type": "css", "dir": "../path/to/css", "tokensDir": "../path/to/design-tokens" },
    // defaults: dir "designsystemet", tokensDir from the design-tokens output, cleanDir false
    { "type": "types", "dir": "../path/to/types", "tokensDir": "../path/to/design-tokens" },
  ],
}

Design tokens are always created first, then CSS, then types. If tokensDir is not set, CSS and types are built from the dir of the design-tokens output.

The types output writes types.d.ts (and the deprecated colors.d.ts), which augment @digdir/designsystemet-types with your theme's color names.

Without a design-tokens output or tokensDir, CSS and types are created directly from the themes, without writing any design tokens. The default, "output": ["css"], creates only CSS this way.

themes is only needed by outputs that are created from themes. To build CSS and types from existing design tokens, leave out themes and set tokensDir:

{
  "output": [
    { "type": "css", "tokensDir": "./design-tokens" },
    { "type": "types", "tokensDir": "./design-tokens" },
  ],
}

Set tailwind on the css output to "v4" or "v3" to also create a <theme>.tailwind.css for that Tailwind version. By default (false) no Tailwind file is created.

The outDir and clean fields are deprecated in favour of output. The CLI will offer to migrate your config file automatically.

Complex config example

Have a look at the *.config.json files under the packages/cli in the Github repo for more complex examples.

Create config from existing tokens

You can get a minimal config file, meaning without overrides, generated from existing design tokens using the following command:

npx @digdir/designsystemet generate-config-from-tokens --dir <path to design tokens> --out <path to config file>

--out defaults to designsystemet.config.json. The generated config uses output, with the design tokens directory written relative to the config file. CSS and types are saved in design-tokens-build in the directory the command was run from, where tokens build saved them.

版本与发布记录

@digdir/designsystemet 共发布 259 个版本,首次发布于 2024/05/21;过去 12 个月发布了 103 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.24.0latest2026/11/092 天前
0.0.0-spike-flatter-design-tokens-20261020130336test2026/10/2022 天前
0.0.0-main-20261016102511next2026/10/1626 天前
0.0.0-config-output-types-202610011312182026/10/011 个月前
0.0.0-config-output-types-202609300936302026/09/301 个月前
1.23.02026/09/251 个月前

关于 @digdir/designsystemet 的常见问题

@digdir/designsystemet 是什么?

CLI for Designsystemet

如何安装 @digdir/designsystemet?

在项目目录运行 npm install @digdir/designsystemet,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 designsystemet,可以用 npx designsystemet 直接运行。

@digdir/designsystemet 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@digdir/designsystemet 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@digdir/designsystemet 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@digdir/designsystemet 可以商用吗?

@digdir/designsystemet 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@digdir/designsystemet 的下载量有多少?

根据 npm 官方下载统计,@digdir/designsystemet 在 2026/10/12 – 2026/11/10 这 30 天内被下载 14,940 次,日均约 498 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@digdir/designsystemet 还在维护吗?

最新版本 1.24.0 发布于 2026/11/09(2 天前);至今共发布 259 个版本,其中过去 12 个月发布了 103 个;首次发布于 2024/05/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。