Skip to content

Commit

Permalink
feat: miniprogram
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed May 22, 2024
1 parent 5556814 commit 780f228
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions scripts/build-miniprogram.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 780f228

Please sign in to comment.