Create an npm package

Last modified by Manuel Leduc on 2026/02/05 17:22

Content

Tutorial

Warning

This is a work in progress.

This tutorial shows how to initialize an npm package in xwiki-platform.

First, pick the location of the new package. Let's call it $LOCATION.

Add the location to the list of packages in the pnpm-workspace.yaml file at the root of the project.

Create a package.json file in $LOCATION

{
  "name": "PACKAGE_NAME",
  "version": "PACKAGE_VERSION",
  "license": "LGPL 2.1",
  "author": "XWiki Org Community <[email protected]>",
  "homepage": "https://xwiki.org/",
  "repository": {
    "type": "git",
    "directory": "$LOCATION",
    "url": "git+https://github.com/xwiki/xwiki-platform.git"
  },
  "bugs": {
    "url": "https://jira.xwiki.org/projects/XWIKI/"
  },
  "type": "module",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./src/index.ts"
    }
  },
  "main": "./src/index.ts",
  "files": [
    "dist",
    "src",
    "!src/**/*.spec.*",
    "!src/**/*.test.*",
    "!src/**/__tests__"
  ],
  "scripts": {
    "api-extractor:ci": "api-extractor run",
    "api-extractor:local": "api-extractor run --local",
    "build": "vite build",
    "clean": "rimraf dist",
    "lint": "eslint \"./src/**/*.{ts,tsx,vue}\" --max-warnings=0",
    "test": "vitest --run",
    "typecheck": "tsc"
  },
  "types": "./dist/index.d.ts",
  "devDependencies": {
    "@microsoft/api-extractor": "catalog:",
    "@xwiki/platform-dev-config": "workspace:*",
    "eslint": "catalog:",
    "typescript": "catalog:",
    "vite": "catalog:",
    "vitest": "catalog:"
  },
  "publishConfig": {
    "exports": {
      ".": {
        "import": {
          "types": "./dist/index.d.ts",
          "default": "./dist/index.es.js"
        },
        "require": {
          "types": "./dist/index.d.cts",
          "default": "./dist/index.umd.js"
        }
      }
    },
    "main": "./dist/index.es.js",
    "types": "./dist/index.d.ts"
  }
}

Get Connected