@forsakringskassan/docs-generator

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

Documentation generator

原始使用文档
文档目录14 节
  1. Setup
  2. Watch (development mode)
  3. Vendor alias
  4. Usage
  5. Using with Vue 2
  6. Using with Vue 3
  7. Styling
  8. Markdown
  9. Frontmatter
  10. Inline tags
  11. Templating
  12. Environment variables
  13. Processors
  14. Matomo

@forsakringskassan/docs-generator

npm install --save-dev --save-exact @forsakringskassan/docs-generator

Setup

Pass import.meta.dirname as the first argument to Generator to use the directory of your configuration file as the working directory. Paths in the generator options are resolved relative to this directory.

Watch (development mode)

You can start a development server with watch for incremental builds using .serve().

import {
    Generator,
    livereloadProcessor,
} from "@forsakringskassan/docs-generator";

const docs = new Generator(import.meta.dirname, {
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",
    processors: [livereloadProcessor({ enabled: true })],
    sourceFiles: [/* ... */],
});

docs.build();
docs.serve();

Vendor alias

Vendor alias is optional, it lets you substitute one package for another when bundling. The example below substitutes the package vue with the package vue/dist/esm.bundle.js. When an alias is given the package can be imported using the given alias as well as the original package name. For instance, when using the following configuration "vue" can be imported and resolved as "vue/dist/esm.bundle.js".

import {
    Generator,
    livereloadProcessor,
} from "@forsakringskassan/docs-generator";

const docs = new Generator(import.meta.dirname, {
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",

    vendor: [
        {
            package: "vue",
            alias: "vue/dist/esm.bundle.js",
        },
    ],
});

Usage

Using with Vue 2

Vue 2 requires an additional dependency to be installed:

npm install --save-dev --save-exact @vue/component-compiler

Create the setup callback in docs/src/setup.ts:

import Vue from "vue";
import { type SetupOptions } from "@forsakringskassan/docs-generator";

/* optionally add global plugins or configuration */
//Vue.use(MyAwesomePlugin);

export function setup(options: SetupOptions): void {
    const { rootComponent, selector } = options;
    const vm = new Vue(rootComponent);
    vm.$mount(selector);
}

Using with Vue 3

Create the setup callback in docs/src/setup.ts:

import { createApp } from "vue";
import { type SetupOptions } from "@forsakringskassan/docs-generator";

export function setup(options: SetupOptions): void {
    const { rootComponent, selector } = options;
    const app = createApp(rootComponent);

    /* optionally add global plugins or configuration */
    //app.use(MyAwesomePlugin);

    app.mount(selector);
}

Styling

Three CSS files are provided:

  • @forsakringskassan/docs-generator/style/index.css (aliased as @forsakringskassan/docs-generator/style)
  • @forsakringskassan/docs-generator/style/core.css
  • @forsakringskassan/docs-generator/style/site.css

core contains the necessary styling for components and elements and site contains the layout, typography etc required for a documentation site to work. index is a combination of the two and should be used in most cases.

Style can be compiled with compileStyle(name, src, [options]):

import { Generator } from "@forsakringskassan/docs-generator";

const docs = new Generator(import.meta.dirname, {
    site: {
        name: "My Awesome Site",
    },
    setupPath: "docs/src/setup.ts",
});

docs.compileStyle("docs", "./docs/src/style.scss", {
    appendTo: "head",
});

Where docs/src/style.scss contains:

@use "~@forsakringskassan/docs-generator/style";

Markdown

To create link to a different document use {@link ID [TITLE]}, e.g.:

See {@link MyAwesomeComponent} for details or the {@link getting-started getting started guide}.

will be rendered as:

<p>
    See
    <a href="./components/my-awesome-component.html">MyAwesomeComponent</a> for
    details or the
    <a href="../guides/getting-started.html">getting started guide</a>.
</p>

The ID can be either the document identifier, name or one of the aliases. The link destination will always be relative to the current document.

Code fence

For configured languages (default html and vue) code fences are run as a live example in the browser with an option to display the source code. The following tags can be used:

  • borderless - removes the border from the example.
  • fullscreen - enable support for viewing the example in fullscreen.
  • static - force code to be rendered without live preview (only syntax highlight).
  • live-example - mark example as containing the LiveExample component.
  • nomarkup - for live examples this hides the syntax highlighted code and only displays the result of the running code.
  • test-id=STRING - Sets the data-test attribute.

static and live are used to manually set whenever the code should be run as a live example or not.

```html static
<p>This is displayed as syntax highlighted code only</p>
```
```js live
alert("This is run in the browser");
```

Examples can be imported using the import directive:

```import
MyAwesomeFile.vue
```

This will search for MyAwesomeFile.vue in the configured exampleFolders. HTML-comments may be placed before or after the filename.

To import an example that uses the LiveExample component you also need to use the live-example tag.

```import live-example
MyAwesomeLiveExampleFile.vue
```

Frontmatter

status

Set a status badge for a component.

The following statuses are recognized:

  • Produktionsklar
  • Deprekerad
  • Experimentell
  • Preliminär
  • Draft (deprecated alias for Preliminär)
  • Beta (deprecated alias for Preliminär)

title

Document title used for <title> and <nav>

short-title

Document title used when a shorter title is needed, e.g. site navigation.

visible

Set to false to hide document from navigation menu. Default true.

include

Set to false to not write the document to file or include as a page. Default true.

Inline tags

Implicit title:

Use the {@@link MyAwesomeComponent} component.

Explicit title:

Use the {@@link MyAwesomeComponent awesome component}.

{@@optional}

Creates a tag (badge) to mark something as optional.

Input:

{@@optional}

Output:

{@optional}

Templating

The Nunjucks templating engine is used for rendering documents to HTML. See templating documentation for help.

These custom filters and tags are available:

container

{% container "awesome-name" %}

Creates a container which processors may inject content into.

Environment variables

DOCS_ICON_LIB

Preferred icon library package name. Defaults to @fkui/icon-lib-default. Makes it possible to dynamically load icons and get access to icon metadata. The library must have been built using @fkui/icon-lib-builder.

const icons = await import(process.env.DOCS_ICON_LIB);

for (const entry of Object.values(icons)) {
    entry.injectSpritesheet();
}

Processors

Matomo

 const docs = new Generator(import.meta.dirname, {
     processors: [
+        matomoProcessor({
+            siteId: "1",
+            apiUrl: "https://matomo.example.net/",
+            trackerUrl: "https://matomo.example.net/",
+        }),
     ],
 });

Optionally set hostname to limit which hostnames can run Matomo analytics:

 const docs = new Generator(import.meta.dirname, {
     processors: [
         matomoProcessor({
             siteId: "1",
             apiUrl: "https://matomo.example.net/",
             trackerUrl: "https://matomo.example.net/",
+            hostname: "docs.example.net",
         }),
     ],
 });

Only the domain must be specified, e.g it should not include https:// or a path /path/to/docs. Multiple hostnames can be specified as an array.

版本与发布记录

@forsakringskassan/docs-generator 共发布 199 个版本,首次发布于 2024/04/12;过去 12 个月发布了 85 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.24.2latest2026/11/123 天前
3.24.12026/11/114 天前
3.24.02026/11/114 天前
3.23.12026/11/069 天前
3.23.02026/11/0115 天前
3.22.32026/10/3016 天前

关于 @forsakringskassan/docs-generator 的常见问题

@forsakringskassan/docs-generator 是什么?

Documentation generator

如何安装 @forsakringskassan/docs-generator?

在项目目录运行 npm install @forsakringskassan/docs-generator,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:he(^1.2)、vue(^3.0.0)、sass(^1.71)、esbuild(0.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@forsakringskassan/docs-generator 支持 TypeScript 吗?

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

@forsakringskassan/docs-generator 支持 ESM 还是 CommonJS?

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

@forsakringskassan/docs-generator 需要什么版本的 Node.js?

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

@forsakringskassan/docs-generator 可以商用吗?

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

@forsakringskassan/docs-generator 的下载量有多少?

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

@forsakringskassan/docs-generator 还在维护吗?

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