From effccb7d2d210a3c0a9bd03ca5d9c740636901e1 Mon Sep 17 00:00:00 2001
From: neverland <jait.chen@foxmail.com>
Date: Sun, 24 Nov 2024 20:09:02 +0800
Subject: [PATCH] chore(vant-compat): use Rslib to build (#13231)

---
 packages/vant-compat/package.json    | 22 ++++----
 packages/vant-compat/rslib.config.ts | 12 +++++
 pnpm-lock.yaml                       | 79 +++++++++++++++++++++++++---
 3 files changed, 94 insertions(+), 19 deletions(-)
 create mode 100644 packages/vant-compat/rslib.config.ts

diff --git a/packages/vant-compat/package.json b/packages/vant-compat/package.json
index 3e1250e96..7b7efac97 100644
--- a/packages/vant-compat/package.json
+++ b/packages/vant-compat/package.json
@@ -2,13 +2,13 @@
   "name": "@vant/compat",
   "version": "1.0.1",
   "description": "Provide Vant 3 compatible behavior for Vant 4",
-  "main": "dist/index.cjs.js",
-  "module": "dist/index.esm.mjs",
+  "main": "dist/index.js",
+  "module": "dist/index.mjs",
   "types": "dist/index.d.ts",
   "exports": {
     ".": {
-      "import": "./dist/index.esm.mjs",
-      "require": "./dist/index.cjs.js"
+      "import": "./dist/index.mjs",
+      "require": "./dist/index.js"
     }
   },
   "sideEffects": false,
@@ -20,11 +20,8 @@
     "registry": "https://registry.npmjs.org/"
   },
   "scripts": {
-    "clean": "rimraf ./dist",
-    "dev": "node ./build.js -w",
-    "build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
-    "build:bundle": "node ./build.js",
-    "build": "pnpm clean && pnpm build:bundle && pnpm build:types",
+    "dev": "rslib dev",
+    "build": "rslib build",
     "release": "vant-cli release"
   },
   "repository": {
@@ -36,11 +33,10 @@
   "author": "chenjiahan",
   "license": "MIT",
   "devDependencies": {
+    "@rslib/core": "^0.1.0",
     "@vue/runtime-core": "^3.5.13",
+    "typescript": "^5.6.3",
     "vant": "workspace:*",
-    "vue": "^3.5.13",
-    "esbuild": "^0.24.0",
-    "rimraf": "^6.0.1",
-    "typescript": "^5.6.3"
+    "vue": "^3.5.13"
   }
 }
diff --git a/packages/vant-compat/rslib.config.ts b/packages/vant-compat/rslib.config.ts
new file mode 100644
index 000000000..33e0f1483
--- /dev/null
+++ b/packages/vant-compat/rslib.config.ts
@@ -0,0 +1,12 @@
+import { defineConfig } from '@rslib/core';
+
+export default defineConfig({
+  lib: [
+    { format: 'esm', syntax: ['Chrome 53'], dts: true },
+    { format: 'cjs', syntax: ['Chrome 53'] },
+  ],
+  output: {
+    target: 'web',
+    externals: ['vant'],
+  },
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3e7ea6772..ec5d6f9d1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -287,15 +287,12 @@ importers:
 
   packages/vant-compat:
     devDependencies:
+      '@rslib/core':
+        specifier: ^0.1.0
+        version: 0.1.0(typescript@5.6.3)
       '@vue/runtime-core':
         specifier: ^3.5.13
         version: 3.5.13
-      esbuild:
-        specifier: ^0.24.0
-        version: 0.24.0
-      rimraf:
-        specifier: ^6.0.1
-        version: 6.0.1
       typescript:
         specifier: ^5.6.3
         version: 5.6.3
@@ -1045,6 +1042,19 @@ packages:
     peerDependencies:
       '@rsbuild/core': 1.x
 
+  '@rslib/core@0.1.0':
+    resolution: {integrity: sha512-CGtHgTgj8BSWdQB7yCpGjr5dd37Y7jj/IH6rAtrYbTJR0/o7dm4QqygdwjR8MHBlD9fYTGu7uWbKRdh6qYXPTw==}
+    engines: {node: '>=16.0.0'}
+    hasBin: true
+    peerDependencies:
+      '@microsoft/api-extractor': ^7
+      typescript: ^5
+    peerDependenciesMeta:
+      '@microsoft/api-extractor':
+        optional: true
+      typescript:
+        optional: true
+
   '@rspack/binding-darwin-arm64@1.1.3':
     resolution: {integrity: sha512-gpLUBMDAS/uEcnE+ODy1ILTeyp1oM4QCq8rRhKHuOfsIe1AZ9Mct59v2omIE/r+R4dnbJ0ikIpto9qJZ6P2u1A==}
     cpu: [arm64]
@@ -1812,6 +1822,14 @@ packages:
   fastq@1.17.1:
     resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==}
 
+  fdir@6.4.2:
+    resolution: {integrity: sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==}
+    peerDependencies:
+      picomatch: ^3 || ^4
+    peerDependenciesMeta:
+      picomatch:
+        optional: true
+
   file-entry-cache@6.0.1:
     resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
     engines: {node: ^10.12.0 || >=12.0.0}
@@ -2350,6 +2368,10 @@ packages:
     resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
     engines: {node: '>=8.6'}
 
+  picomatch@4.0.2:
+    resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==}
+    engines: {node: '>=12'}
+
   pify@4.0.1:
     resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
     engines: {node: '>=6'}
@@ -2449,6 +2471,19 @@ packages:
   rrweb-cssom@0.7.1:
     resolution: {integrity: sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==}
 
+  rsbuild-plugin-dts@0.1.0:
+    resolution: {integrity: sha512-8HE2aGkseyrkNSPmJLVEgqIvaTDWGJYE5l6Hfrf94mFzAFcbtHOrYTr4aR/zw90x+BY3sMfE3bMBj/wR9AnxiA==}
+    engines: {node: '>=16.0.0'}
+    peerDependencies:
+      '@microsoft/api-extractor': ^7
+      '@rsbuild/core': 1.x
+      typescript: ^5
+    peerDependenciesMeta:
+      '@microsoft/api-extractor':
+        optional: true
+      typescript:
+        optional: true
+
   rslog@1.2.3:
     resolution: {integrity: sha512-antALPJaKBRPBU1X2q9t085K4htWDOOv/K1qhTUk7h0l1ePU/KbDqKJn19eKP0dk7PqMioeA0+fu3gyPXCsXxQ==}
     engines: {node: '>=14.17.6'}
@@ -2744,6 +2779,10 @@ packages:
   tinyexec@0.3.1:
     resolution: {integrity: sha512-WiCJLEECkO18gwqIp6+hJg0//p23HXp4S+gGtAKu3mI2F2/sXC4FvHvXvB0zJVVaTPhx1/tOwdbRsa1sOBIKqQ==}
 
+  tinyglobby@0.2.10:
+    resolution: {integrity: sha512-Zc+8eJlFMvgatPZTl6A9L/yht8QqdmUNtURHaKZLmKBE12hNPSrqNkUp2cs3M/UKmNVVAMFQYSjYIVHDjW5zew==}
+    engines: {node: '>=12.0.0'}
+
   tinypool@1.0.1:
     resolution: {integrity: sha512-URZYihUbRPcGv95En+sz6MfghfIc2OJ1sv/RmhWZLouPY0/8Vo80viwPvg3dlaS9fuq7fQMEfgRRK7BBZThBEA==}
     engines: {node: ^18.0.0 || >=20.0.0}
@@ -3664,6 +3703,14 @@ snapshots:
       - vue
       - webpack-cli
 
+  '@rslib/core@0.1.0(typescript@5.6.3)':
+    dependencies:
+      '@rsbuild/core': 1.1.4
+      rsbuild-plugin-dts: 0.1.0(@rsbuild/core@1.1.4)(typescript@5.6.3)
+      tinyglobby: 0.2.10
+    optionalDependencies:
+      typescript: 5.6.3
+
   '@rspack/binding-darwin-arm64@1.1.3':
     optional: true
 
@@ -4603,6 +4650,10 @@ snapshots:
     dependencies:
       reusify: 1.0.4
 
+  fdir@6.4.2(picomatch@4.0.2):
+    optionalDependencies:
+      picomatch: 4.0.2
+
   file-entry-cache@6.0.1:
     dependencies:
       flat-cache: 3.2.0
@@ -5161,6 +5212,8 @@ snapshots:
 
   picomatch@2.3.1: {}
 
+  picomatch@4.0.2: {}
+
   pify@4.0.1:
     optional: true
 
@@ -5251,6 +5304,15 @@ snapshots:
 
   rrweb-cssom@0.7.1: {}
 
+  rsbuild-plugin-dts@0.1.0(@rsbuild/core@1.1.4)(typescript@5.6.3):
+    dependencies:
+      '@rsbuild/core': 1.1.4
+      magic-string: 0.30.12
+      picocolors: 1.1.1
+      tinyglobby: 0.2.10
+    optionalDependencies:
+      typescript: 5.6.3
+
   rslog@1.2.3: {}
 
   rspack-plugin-virtual-module@0.1.13:
@@ -5490,6 +5552,11 @@ snapshots:
 
   tinyexec@0.3.1: {}
 
+  tinyglobby@0.2.10:
+    dependencies:
+      fdir: 6.4.2(picomatch@4.0.2)
+      picomatch: 4.0.2
+
   tinypool@1.0.1: {}
 
   tinyrainbow@1.2.0: {}