From 60fa6ba082c50d57ec4abecb196573f4100636d2 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 14 Jul 2022 16:41:54 +0800 Subject: [PATCH] docs: update library mode info (#9102) --- docs/guide/build.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/guide/build.md b/docs/guide/build.md index a6bd0a5106587a..5fe3c2a78e25f8 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -163,8 +163,8 @@ Running `vite build` with this config uses a Rollup preset that is oriented towa ``` $ vite build building for production... -[write] my-lib.mjs 0.08kb, brotli: 0.07kb -[write] my-lib.umd.js 0.30kb, brotli: 0.16kb +dist/my-lib.js 0.08 KiB / gzip: 0.07 KiB +dist/my-lib.umd.cjs 0.30 KiB / gzip: 0.16 KiB ``` Recommended `package.json` for your lib: @@ -172,18 +172,23 @@ Recommended `package.json` for your lib: ```json { "name": "my-lib", + "type": "module", "files": ["dist"], - "main": "./dist/my-lib.umd.js", - "module": "./dist/my-lib.mjs", + "main": "./dist/my-lib.umd.cjs", + "module": "./dist/my-lib.js", "exports": { ".": { - "import": "./dist/my-lib.mjs", - "require": "./dist/my-lib.umd.js" + "import": "./dist/my-lib.js", + "require": "./dist/my-lib.umd.cjs" } } } ``` +::: tip Note +If the `package.json` does not contain `"type": "module"`, Vite will generate different file extensions for Node.js compatibility. `.js` will become `.mjs` and `.cjs` will become `.js`. +::: + ## Advanced Base Options ::: warning