Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(upload): 代码优化 #2705

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/empty-dogs-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@hi-ui/upload": minor
---

perf: 依赖项中增加 @hi-ui/message,否则打包时会将多余代码打进去
feat: 暴露出单个不同类型的上传组件,支持按需引入,对 Tree Shaking 友好
5 changes: 5 additions & 0 deletions .changeset/popular-phones-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

perf(upload): 代码优化,降低打包体积
1 change: 1 addition & 0 deletions packages/ui/upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@hi-ui/env": "^4.0.4",
"@hi-ui/file-select": "^4.0.7",
"@hi-ui/icons": "^4.0.18",
"@hi-ui/message": "^4.0.7",
"@hi-ui/modal": "^4.0.15",
"@hi-ui/preview": "^4.0.8",
"@hi-ui/use-id": "^4.0.4",
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/upload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ import './styles/index.scss'
export * from './Upload'
export { Upload as default } from './Upload'

export { NormalUpload } from './NormalUpload'
export { DragUpload } from './DragUpload'
export { PictureListUpload } from './PictureListUpload'
export { PictureUpload } from './PictureUpload'
export { AvatarUpload } from './AvatarUpload'

export * from './types'
1 change: 1 addition & 0 deletions packages/ui/upload/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Upload from '../src'

export * from './basic.stories'
export * from './single-import.stories'
export * from './draggable.stories'
export * from './picture-card.stories'
export * from './photo.stories'
Expand Down
26 changes: 26 additions & 0 deletions packages/ui/upload/stories/single-import.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { NormalUpload, DragUpload, PictureUpload, PictureListUpload, AvatarUpload } from '../src'

/**
* @title 单个导入,按需引用
* @desc 建议采用该方式引用,有利用打包时做 Tree Shaking
*/
export const SingleImport = () => {
return (
<>
<h1>SingleImport</h1>
<div className="upload-single-import__wrap">
<NormalUpload
uploadAction="https://jsonplaceholder.typicode.com/posts/"
tips="仅支持 jpg/png 文件,且不超过 500kb"
accept="image/png,image/jpg"
headers={{ name: 'mi' }}
name={'files[]'}
onChange={(file, fileList, response) => {
console.log('upload callback', file, fileList, response)
}}
/>
</div>
</>
)
}