From 54c23b7b4df8d4a45f573685455ee57d204cb7f5 Mon Sep 17 00:00:00 2001 From: luoanbing Date: Sat, 16 Mar 2024 00:58:48 +0800 Subject: [PATCH] =?UTF-8?q?build=E6=8B=86=E5=88=86antd=E5=92=8C=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 15 ++++++++--- rollup.config.mjs | 63 ++++++++++++++++++++++++--------------------- src/forUmd.ts | 6 +++++ src/index.ts | 2 +- test/package.json | 3 ++- test/pnpm-lock.yaml | 8 ++++++ test/src/App.tsx | 3 ++- test/tsconfig.json | 5 ++-- test/vite.config.ts | 5 ++-- 9 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 src/forUmd.ts diff --git a/package.json b/package.json index 89313ba..dae9305 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,19 @@ "mui", "typescript" ], - "main": "dist/index.cjs.js", - "module": "dist/index.esm.js", + "exports": { + ".": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm.js", + "types": "./dist/index.d.ts" + }, + "./Antd_5": { + "require": "./dist/Antd_5.cjs.js", + "import": "./dist/Antd_5.esm.js", + "types": "./dist/Antd_5.d.ts" + } + }, "browser": "dist/index.umd.js", - "types": "dist/index.d.ts", "devDependencies": { "@changesets/cli": "^2.27.1", "@nextui-org/react": "^2.2.9", diff --git a/rollup.config.mjs b/rollup.config.mjs index 923a461..134fb77 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -7,11 +7,40 @@ import { uglify } from 'rollup-plugin-uglify' import dts from 'rollup-plugin-dts' import pkg from './package.json' assert { type: 'json' } + +const defineLib = ({ input, outputName }) => { + return [ + { + input, + external: ['react'], + output: [ + { file: `dist/${outputName}.cjs.js`, format: 'cjs' }, + { file: `dist/${outputName}.esm.js`, format: 'es' } + ], + plugins: [ + typescript(), + commonjs(), // so Rollup can convert `ms` to an ES module + ...(process.env.NODE_ENV === 'development' ? [] : [terser(), uglify()]) + ] + }, + + // 声明 + { + input, + external: ['react', '@nextui-org/react', 'antd'], + output: [ + { + file: `dist/${outputName}.d.ts` + } + ], + plugins: [dts()] + } + ] +} /** @type {import('rollup').RollupOptions} */ export default [ - // browser-friendly UMD build { - input: 'src/index.ts', + input: 'src/forUmd.ts', output: { name: 'hookFormReact', file: pkg.browser, @@ -25,32 +54,6 @@ export default [ ...(process.env.NODE_ENV === 'development' ? [] : [terser(), uglify()]) ] }, - - // CommonJS (for Node) and ES module (for bundlers) build. - // (We could have three entries in the configuration array - // instead of two, but it's quicker to generate multiple - // builds from a single configuration where possible, using - // an array for the `output` option, where we can specify - // `file` and `format` for each target) - { - input: 'src/index.ts', - external: ['react'], - output: [ - { file: pkg.main, format: 'cjs' }, - { file: pkg.module, format: 'es' } - ], - plugins: [typescript()] - }, - - // 声明 - { - input: 'src/index.ts', - external: ['react', '@nextui-org/react', 'antd'], - output: [ - { - file: './dist/index.d.ts' - } - ], - plugins: [dts()] - } + ...defineLib({ input: 'src/Antd_5/index.tsx', outputName: 'Antd_5', name: 'hookFormReact' }), + ...defineLib({ input: 'src/index.ts', outputName: 'index', name: 'hookFormReact' }) ] diff --git a/src/forUmd.ts b/src/forUmd.ts new file mode 100644 index 0000000..43433ae --- /dev/null +++ b/src/forUmd.ts @@ -0,0 +1,6 @@ +export * from './useObjectData' +export * from './Verifications' +export * from './NextUI_2_2' +export * from './useFormData' +export * from './useAttr' +export * from './Antd_5' diff --git a/src/index.ts b/src/index.ts index 43433ae..edfde0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,4 +3,4 @@ export * from './Verifications' export * from './NextUI_2_2' export * from './useFormData' export * from './useAttr' -export * from './Antd_5' +// export * from './Antd_5' diff --git a/test/package.json b/test/package.json index d8fcb52..a2b2bcc 100644 --- a/test/package.json +++ b/test/package.json @@ -16,7 +16,8 @@ "framer-motion": "^11.0.8", "react": "^18.2.0", "react-dom": "^18.2.0", - "tailwindcss": "^3.4.1" + "tailwindcss": "^3.4.1", + "hook-form-react": "file:../" }, "devDependencies": { "@types/node": "^20.11.25", diff --git a/test/pnpm-lock.yaml b/test/pnpm-lock.yaml index ebe2b5a..6ae6734 100644 --- a/test/pnpm-lock.yaml +++ b/test/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: framer-motion: specifier: ^11.0.8 version: 11.0.8(react-dom@18.2.0)(react@18.2.0) + hook-form-react: + specifier: file:../ + version: file:.. react: specifier: ^18.2.0 version: 18.2.0 @@ -5770,3 +5773,8 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + file:..: + resolution: {directory: .., type: directory} + name: hook-form-react + dev: false diff --git a/test/src/App.tsx b/test/src/App.tsx index 6f3d503..aec4a45 100644 --- a/test/src/App.tsx +++ b/test/src/App.tsx @@ -1,4 +1,5 @@ -import { Antd_5, useAttr, useFormData, useSubFormData, Verifications } from 'hook-form-react' +import { useAttr, useFormData, useSubFormData, Verifications } from 'hook-form-react' +import { Antd_5 } from 'hook-form-react/Antd_5' import { Button, Checkbox, diff --git a/test/tsconfig.json b/test/tsconfig.json index 00a14b9..99df6ee 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -21,8 +21,9 @@ "noFallthroughCasesInSwitch": true, "baseUrl": "./", "paths": { - "@/*": ["src/*"], - "hook-form-react": ["../src/index.ts"] + "@/*": ["src/*"] + // "hook-form-react": ["../src/index.ts"], + // "hook-form-react/Antd_5": ["../src/Antd_5/index.tsx"] } }, "include": ["src"], diff --git a/test/vite.config.ts b/test/vite.config.ts index a76d83e..476fffc 100644 --- a/test/vite.config.ts +++ b/test/vite.config.ts @@ -11,8 +11,9 @@ export default defineConfig({ }, resolve: { alias: { - '@': path.resolve(__dirname, 'src'), - 'hook-form-react': path.resolve(__dirname, '../src/index.ts') + '@': path.resolve(__dirname, 'src') + // 'hook-form-react': path.resolve(__dirname, '../src/index.ts'), + // 'hook-form-react/Antd_5': path.resolve(__dirname, '../src/Antd_5/index.tsx') } } })