refactor: translate server side code into esm

This commit is contained in:
moonrailgun 2024-07-28 19:39:15 +08:00
parent 37757f6563
commit 5dca262482
5 changed files with 976 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,12 @@
"name": "@tianji/server",
"private": true,
"description": "",
"main": "index.js",
"type": "module",
"engines": {
"node": ">=20.11.0"
},
"scripts": {
"dev": "nodemon",
"dev": "tsx watch --env-file=.env ./main.ts",
"build": "tsc -p tsconfig.server.json",
"postinstall": "pnpm db:generate",
"check:type": "tsc --noEmit --skipLibCheck --module esnext",
@ -101,6 +104,7 @@
"prisma-zod-generator": "0.8.13",
"supertest": "^6.3.4",
"tailwindcss": "^3.3.5",
"tsx": "^4.16.2",
"vite": "^5.0.12",
"vitest": "^1.2.1"
}

View File

@ -1,4 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./**/*"]
"compilerOptions": {
"module": "NodeNext",
"esModuleInterop": true,
"target": "esnext",
"noImplicitAny": true,
"moduleResolution": "NodeNext",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"skipLibCheck": true,
"strict": true,
"typeRoots": ["types/", "node_modules/@types"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@ -3,17 +3,15 @@
"version": "1.0.0",
"private": true,
"description": "",
"types": "./dist/cjs/src/shared/src/index.d.ts",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/esm/src/shared/src/index.js",
"require": "./dist/cjs/src/shared/src/index.js"
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"scripts": {
"check:type": "tsc --noEmit --skipLibCheck --module esnext",
"test": "vitest",
"build": "concurrently npm:build:cjs npm:build:esm",
"build:cjs": "tsc --module commonjs --outDir ./dist/cjs",
"build:esm": "tsc --module esnext --outDir ./dist/esm",
"build": "tsup",
"postinstall": "pnpm build"
},
"keywords": [],
@ -22,6 +20,7 @@
"dayjs": "^1.11.9"
},
"devDependencies": {
"tsup": "^8.2.3",
"vitest": "^1.2.1"
}
}

17
src/shared/tsup.config.ts Normal file
View File

@ -0,0 +1,17 @@
import { defineConfig } from 'tsup';
export default defineConfig((options) => {
return {
clean: true,
dts: true,
entry: ['src/index.ts'],
outDir: 'dist',
format: ['cjs', 'esm'],
minify: !options.watch,
treeshake: false,
tsconfig: 'tsconfig.json',
splitting: false,
sourcemap: true,
external: ['react'],
};
});