Father (NPM Package Build Tool)
Father is a comprehensive NPM package development tool within the UmiJS ecosystem, designed to streamline the building, generating, and publishing of JavaScript and TypeScript packages. It features a dual-mode build system: 'Bundless' for ESModule and CommonJS outputs, leveraging esbuild, Babel, or SWC; and 'Bundle' for UMD artifacts powered by Webpack. The package, currently at version 4.6.18, maintains an active release cadence with frequent minor updates and patches. Its key differentiators include robust type generation for TypeScript, persistent caching for accelerated builds, and integrated project health checks to prevent common development pitfalls. Father also offers micro-generators for common engineering tasks and experimental dependency pre-bundling to enhance stability in Node.js frameworks and libraries.
Common errors
-
Error: Cannot find module 'father'
cause The `father` package is not installed in the project or is not accessible in the current execution environment.fixRun `npm install father` or `pnpm install father` or `yarn add father` in your project's root directory. Ensure it's listed in `devDependencies`. -
TypeScript error: Argument of type '{ ... }' is not assignable to parameter of type 'IFatherConfig'.cause The configuration object passed to `defineConfig` in `father.config.ts` does not conform to the `IFatherConfig` type definition.fixReview your `father.config.ts` against the official documentation and the type definitions (`IFatherConfig`, `IBundlessConfig`, etc.) for any incorrect or missing properties. Your IDE should provide type hints. -
Build failed: 'output' cannot be set for 'esm' or 'cjs' when 'auto' is enabled.
cause Conflicting configuration where an explicit output path is provided for ESModule or CommonJS builds while the `auto` output directory generation is also active.fixEither remove the `output` property from the `esm` or `cjs` configuration block, or disable `auto` if you intend to specify custom output paths manually.
Warnings
- breaking Upgrading from Father 2.x to Father 4.x introduces significant breaking changes due to a complete rewrite and architectural shifts. Direct upgrade often requires reconfiguring build processes.
- gotcha Incorrectly configuring Bundless vs. Bundle modes, or choosing the wrong build core (esbuild, Babel, SWC for Bundless; Webpack for Bundle) can lead to unexpected output formats or compatibility issues.
- gotcha While persistent caching is a feature, in rare cases it might lead to stale build artifacts if the cache is not properly invalidated after certain changes (e.g., changes to external dependencies not tracked by Father).
Install
-
npm install father -
yarn add father -
pnpm add father
Imports
- defineConfig
const { defineConfig } = require('father');import { defineConfig } from 'father'; - IFatherConfig
import { IFatherConfig } from 'father';import type { IFatherConfig } from 'father'; - IBundlessConfig
import { IBundlessConfig } from 'father';import type { IBundlessConfig } from 'father';
Quickstart
{
"name": "my-package",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "father build"
},
"devDependencies": {
"father": "^4.6.18",
"typescript": "^5.0.0"
}
}
// father.config.ts
import { defineConfig } from 'father';
export default defineConfig({
esm: { type: 'babel', importLibToEs: true },
cjs: { type: 'babel', lazy: true },
// Optional: UMD build for browser compatibility
// umd: { name: 'myPackage', output: 'dist' },
// Persistent caching for faster rebuilds
extraBabelPlugins: [
['babel-plugin-import', { libraryName: 'lodash', libraryDirectory: 'es' }]
],
targets: { esmodules: true, node: 14 }
});
// src/index.ts
export const greet = (name: string): string => `Hello, ${name} from Father!`;
export const add = (a: number, b: number): number => a + b;