@forsakringskassan/vite-lib-config

中文文档
5.15.2发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2.6万

Försäkringskassan toolchain to build libraries with Vite

原始使用文档
文档目录11 节
  1. Configuration
  2. Bundled dependencies
  3. Usage
  4. babel.config.js
  5. vite.config.ts
  6. package.json
  7. Optional: API Extractor
  8. Optional: build pageobjects and selectors
  9. Optional: build mocks
  10. Dev-server
  11. Appending Plugins

@forsakringskassan/vite-lib-config

Toolchain for building Vue framework libraries.

  • Hybrid ESM/CJS packages.
  • Transpiled with Babel.
  • Supports monorepo.
  • Optional: build pageobjects, selectors, and mocks.
  • Optional: shared typescript configuration.

Configuration

Use fk-write-config to write boilerplate configuration files to the repository:

fk-write-config

API Extractor is optiona and must be enabled with --with-api-extractor.

By default it assumes vitest is used as test runner, use --with-jest or --with-vitest to explicitly set a test runner.

Bundled dependencies

By default all dependencies (dependencies and peerDependencies) are marked as external and not bundled in output files. This can be overriden by setting externalDependencies in package.json:

     "dependencies": {
         "lodash": "^4.17.20"
     },
+    "externalDependencies": [
+        "lodash"
+    ],

Usage

babel.config.js

module.exports = {
    presets: ["@forsakringskassan/vite-lib-config/babel"],
};

vite.config.ts

import { defineConfig } from "@forsakringskassan/vite-lib-config/vite";

export default defineConfig();

In addition to the regular Vite configuration you can also pass the optional fk property:

export interface FKConfig {
    /** path to component to mount by default (default `src/dev-vite/app.vue`) */
    entrypoint?: string;
    /** mocks to configure with apimock-express (default `[]`) */
    mocks?: MockEntry[] | Mock[]
}

package.json

{
    "scripts": {
        "build": "fk-build-vue-lib"
    }
}

Optional: API Extractor

 {
     "scripts": {
         "build": "fk-build-vue-lib",
+        "postbuild": "fk-api-extractor api-extractor.json",
     }
 }

Multiple files or globs can be given:

fk-api-extractor api-extractor.*.json

To fix global module augmentations use:

fk-api-extractor --patch-augmentations

Use --help to see full description.

Optional: build pageobjects and selectors

 {
     "scripts": {
         "build": "fk-build-vue-lib",
+        "build:selectors": "fk-build-selectors",
     }
 }

If src/selectors/index.ts it will be built to dist/${format}/selectors.${cjs,mjs}.

If src/cypress/index.ts it will be built to dist/${format}/cypress.${cjs,mjs}.

Optional: build mocks

 {
     "scripts": {
         "build": "fk-build-vue-lib --mocks",
     }
 }

This builds src/mocks/index.ts to dist/${format}/mocks.${cjs,mjs}. The file must export a list of mocks of type apimock-express (MockEntry[] or Mock[]).

src/mocks/index.ts

import { type Mock } from "@forsakringskassan/apimock-express";

const mocks: Mock[] = [...];
export default mocks;

Dev-server

{
    "scripts": {
        "start": "vite"
    }
}

Create src/local.{ts,mts,mjs,js} exporting a single function setup:

import { createApp } from "vue";
import { type SetupOptions } from "@forsakringskassan/vite-lib-config";

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

If the setup function is async (i.e. returns a Promise) it will be awaited before continuing.

Create src/vite-dev/app.vue containing the root component you want to serve as a development environment.

When running in dev mode an optional filename (or part of filename) can be given to run instead of default src/vite-dev/app.vue:

vite -- MyAwesomeExample

would search for .vue files matching the given pattern (fuzzy) in these folders:

  • **/docs
  • **/examples
  • **/test

Appending Plugins

If you need to use custom plugins in your library, remember to also include the default plugins, these will otherwise by overwritten.

vite.config.ts

import {
    defineConfig,
    defaultPlugins,
} from "@forsakringskassan/vite-lib-config/vite";

export default defineConfig({
    plugins: [...defaultPlugins, myFancyPlugin],
});

版本与发布记录

@forsakringskassan/vite-lib-config 共发布 139 个版本,首次发布于 2024/03/11;过去 12 个月发布了 82 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.15.2latest2026/11/069 天前
5.15.12026/11/0411 天前
5.15.02026/11/0213 天前
5.14.12026/10/3116 天前
5.13.62026/10/2917 天前
5.13.52026/10/2917 天前

关于 @forsakringskassan/vite-lib-config 的常见问题

@forsakringskassan/vite-lib-config 是什么?

Försäkringskassan toolchain to build libraries with Vite

如何安装 @forsakringskassan/vite-lib-config?

在项目目录运行 npm install @forsakringskassan/vite-lib-config,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.0.0)、vite(^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0)、prettier(^3.0.0)、typescript(^5.0.2 || ^6.0.2 || ^7.0.0)、vue-router(^5.0.0)、@babel/core(^7.22.0)、@fkui/tsconfig(>= 6.3.0)、@forsakringskassan/apimock-express(^1.1.0 || ^2.0.0 || ^3.0.0 || ^4.0.0)、@babel/plugin-transform-nullish-coalescing-operator(^7.22.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 fk-write-config、fk-api-extractor、fk-build-vue-lib、fk-build-selectors,可以用 npx fk-write-config 直接运行。

@forsakringskassan/vite-lib-config 支持 TypeScript 吗?

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

@forsakringskassan/vite-lib-config 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@forsakringskassan/vite-lib-config 需要什么版本的 Node.js?

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

@forsakringskassan/vite-lib-config 可以商用吗?

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

@forsakringskassan/vite-lib-config 的下载量有多少?

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

@forsakringskassan/vite-lib-config 还在维护吗?

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