Skip to content

Commit

Permalink
build拆分antd和核心库
Browse files Browse the repository at this point in the history
  • Loading branch information
luoanb committed Mar 15, 2024
1 parent 91376a8 commit 54c23b7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 40 deletions.
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 33 additions & 30 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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' })
]
6 changes: 6 additions & 0 deletions src/forUmd.ts
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions test/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 3 additions & 2 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
5 changes: 3 additions & 2 deletions test/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
})

0 comments on commit 54c23b7

Please sign in to comment.