Skip to content

Commit

Permalink
优化打包分块和代码逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Apr 14, 2024
1 parent 513d812 commit 9db2f9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ function App() {
// 首次渲染时从 localforage 中获取已收藏图片列表
useEffect(() => {
localforage.getItem('staredImages')
.then(staredImages => {
if (staredImages) {
const initialImages = staredImages.map(image => {
const url = URL.createObjectURL(image.blob)
const hash = image.hash
return { url, type: 'image', star: 'stared', hash }
})
initialImages.reverse()
setImages(initialImages)
}
})
return () => setImages([])
.then(staredImages => { if (staredImages) {
// 将已收藏图片列表转换为图片信息列表
const initialImages = staredImages.map(image => {
const url = URL.createObjectURL(image.blob)
const hash = image.hash
return { url, type: 'image', star: 'stared', hash }
})
// 倒转并设置图片信息列表
initialImages.reverse()
setImages(initialImages)
}})
}, [setImages])

return (
Expand Down
9 changes: 8 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
build: {
target: ['chrome89', 'firefox89', 'safari15', 'edge89']
target: ['chrome89', 'firefox89', 'safari15', 'edge89'],
rollupOptions: {
output: {
manualChunks: {
antd: ['antd', '@ant-design/icons'],
},
},
},
}
})

0 comments on commit 9db2f9c

Please sign in to comment.