diff --git a/package.json b/package.json index 76dcb6db..f1872062 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "files": ["./dist"], "main": "./dist/cjs/full/index.js", "module": "./dist/es/full/index.js", + "miniprogram": "./dist/miniprogram/full", "exports": { ".": { "import": "./dist/es/full/index.js", @@ -82,9 +83,11 @@ "build:es": "vite build", "build:cjs": "tsx ./scripts/build-cjs.ts", "build:iife": "tsx ./scripts/build-iife.ts", - "build": "conc \"npm:build:es\" \"npm:build:cjs\" \"npm:build:iife\"", + "build:miniprogram": "tsx ./scripts/build-miniprogram.ts", + "build": "conc \"npm:build:es\" \"npm:build:cjs\" \"npm:build:iife\" \"npm:build:miniprogram\"", "postbuild:es": "tsc --declarationDir ./dist/es", "postbuild:cjs": "tsc --declarationDir ./dist/cjs", + "postbuild:miniprogram": "tsc --declarationDir ./dist/miniprogram", "postbuild": "conc \"npm:copy:wasm\" \"npm:docs:build\"", "build:all": "npm run submodule:init && npm run cmake && npm run build:wasm && npm run build", "preview": "vite preview", diff --git a/scripts/build-miniprogram.ts b/scripts/build-miniprogram.ts new file mode 100644 index 00000000..fcad232f --- /dev/null +++ b/scripts/build-miniprogram.ts @@ -0,0 +1,25 @@ +import { writeFile } from "node:fs/promises"; +import { type LibraryOptions, build } from "vite"; +import viteConfig from "../vite.config.js"; + +async function buildCjs() { + await build({ + ...viteConfig, + build: { + ...viteConfig.build, + target: ["es2018"], + lib: { + ...(viteConfig.build?.lib as LibraryOptions), + formats: ["cjs"], + }, + outDir: "dist/miniprogram", + }, + configFile: false, + }); + await writeFile( + "dist/miniprogram/package.json", + `${JSON.stringify({ type: "commonjs" }, undefined, 2)}\n`, + ); +} + +buildCjs();