npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

@pika/pack• npm package building, reimagined.

@pika/pack helps you build amazing packages without the hassle:


Simple⚡️Use pre-configured plugins to build your package for you.
Flexible🏋️‍♀️Choose plugins and optimizations to match your needs.
Holistic⚛️Let us build the entire package... including package.json.

Quickstart


  1. ``` shell
  2. npx @pika/pack                           # Run once.
  3. npm install --dev @pika/pack             # Or, run multiple times using "pika pack" in any package.json scripts
  4. ```

😎🆒! So now what? If you run pika build with an empty pipeline, you'll get an empty package build. @pika/packlets you connect pre-configured plugins to build and optimize your package for you. Plugins wrap already-popular tools like Babel and Rollup with npm-optimized config options, removing the need to fiddle with much (if any) configuration yourself. You even get a generated package.json manifest configured for you automatically.

1. Create a project pipeline out of simple, pluggable builders.


  1. ``` js
  2. // Before: Your top-level package.json manifest:
  3. {
  4.   "name": "simple-package",
  5.   "version": "1.0.0",
  6.   "@pika/pack": {
  7.     "pipeline": [
  8.       ["@pika/plugin-standard-pkg", {"exclude": ["__tests__/**/*"]}],
  9.       ["@pika/plugin-build-node"],
  10.       ["@pika/plugin-build-web"],
  11.       ["@pika/plugin-build-types"]
  12.     ]
  13.   }
  14. }
  15. ```

Builders are simple, single-purpose build plugins defined in your package.json. For example, @pika/plugin-build-node & @pika/plugin-build-web build your package for those different environments. Other, more interesting builders can bundle your web build for unpkg, generate TypeScript definitions from your JavaScript, addon a standard CLI wrapper for Node.js builds, and even compile non-JS languages to WASM (with JS bindings added).

2. Builders handle everything, including package configuration.


  1. ``` js
  2. // After: your built "pkg/" package.json manifest:
  3. {
  4.   "name": "simple-package",
  5.   "version": "1.0.0",
  6.   // Multiple distributions, built & configured automatically:
  7.   "esnext": "dist-src/index.js",
  8.   "main": "dist-node/index.js",
  9.   "module": "dist-web/index.js",
  10.   "types": "dist-types/index.d.ts",
  11.   // With sensible package defaults:
  12.   "sideEffects": false,
  13.   "files": ["dist-*/", "assets/", "bin/"]
  14. }
  15. ```

This is all possible because @pika/packbuilds your entire package: code, assets, and even package.json manifest. By building the entire package, you end up with a fully-built pkg/ directory, ready to publish. Entry points like "main", "module", "umd:main", "types", "unpkg", "files", and even advanced options like "sideEffects" are all handled by your build pipeline.

Build Plugins


Check out the full list of official & community-written @pika/pack plugins!

Lerna Support


Curious about integrating @pika/pack with Lerna? Our official collection of plugins is a Lerna repo that uses @pika/pack to build each package! Check it out to see how easy it is to use the two tools together.
Last Updated: 2023-05-15 10:22:02