Wiki source code of Create an npm package

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

Hide last authors
Manuel Leduc 4.1 1 {{warning}}
2 This is a work in progress.
3 {{/warning}}
4
Manuel Leduc 1.1 5 This tutorial shows how to initialize an npm package in ##xwiki-platform##.
Manuel Leduc 2.1 6
7 First, pick the location of the new package. Let's call it ##$LOCATION##.
8
9 Add the location to the list of packages in the ##pnpm-workspace.yaml## file at the root of the project.
10
11 Create a package.json file in ##$LOCATION##
12
13 {{code language="json"}}
14 {
15 "name": "PACKAGE_NAME",
16 "version": "PACKAGE_VERSION",
17 "license": "LGPL 2.1",
18 "author": "XWiki Org Community <[email protected]>",
19 "homepage": "https://xwiki.org/",
20 "repository": {
21 "type": "git",
22 "directory": "$LOCATION",
23 "url": "git+https://github.com/xwiki/xwiki-platform.git"
24 },
25 "bugs": {
26 "url": "https://jira.xwiki.org/projects/XWIKI/"
27 },
28 "type": "module",
29 "exports": {
30 ".": {
31 "types": "./dist/index.d.ts",
32 "import": "./src/index.ts"
33 }
34 },
35 "main": "./src/index.ts",
36 "files": [
37 "dist",
38 "src",
39 "!src/**/*.spec.*",
40 "!src/**/*.test.*",
41 "!src/**/__tests__"
42 ],
43 "scripts": {
44 "api-extractor:ci": "api-extractor run",
45 "api-extractor:local": "api-extractor run --local",
46 "build": "vite build",
47 "clean": "rimraf dist",
48 "lint": "eslint \"./src/**/*.{ts,tsx,vue}\" --max-warnings=0",
49 "test": "vitest --run",
50 "typecheck": "tsc"
51 },
52 "types": "./dist/index.d.ts",
53 "devDependencies": {
54 "@microsoft/api-extractor": "catalog:",
55 "@xwiki/platform-dev-config": "workspace:*",
56 "eslint": "catalog:",
57 "typescript": "catalog:",
58 "vite": "catalog:",
59 "vitest": "catalog:"
60 },
61 "publishConfig": {
62 "exports": {
63 ".": {
64 "import": {
65 "types": "./dist/index.d.ts",
66 "default": "./dist/index.es.js"
67 },
68 "require": {
69 "types": "./dist/index.d.cts",
70 "default": "./dist/index.umd.js"
71 }
72 }
73 },
74 "main": "./dist/index.es.js",
75 "types": "./dist/index.d.ts"
76 }
77 }
78 {{/code}}
79
Manuel Leduc 4.1 80

Get Connected