Commit 1872478a authored by 申中慧's avatar 申中慧

fix:打包优化

parent e406df68
...@@ -126,12 +126,15 @@ ...@@ -126,12 +126,15 @@
"postcss": "^8.4.29", "postcss": "^8.4.29",
"prettier": "^2.8.4", "prettier": "^2.8.4",
"qs": "^6.11.0", "qs": "^6.11.0",
"rollup-plugin-visualizer": "^5.9.2",
"stylelint": "^15.2.0", "stylelint": "^15.2.0",
"stylelint-config-standard": "^30.0.1", "stylelint-config-standard": "^30.0.1",
"tailwindcss": "^3.3.3", "tailwindcss": "^3.3.3",
"typescript": "^4.9.3", "typescript": "^4.9.3",
"vite": "^4.1.0", "vite": "^4.1.0",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-eslint": "^1.8.1", "vite-plugin-eslint": "^1.8.1",
"vite-plugin-imagemin": "^0.6.1",
"vite-plugin-mock": "^2.9.6" "vite-plugin-mock": "^2.9.6"
} }
} }
\ No newline at end of file
This diff is collapsed.
...@@ -207,6 +207,7 @@ const LayoutPage: React.FC = () => { ...@@ -207,6 +207,7 @@ const LayoutPage: React.FC = () => {
location={{ location={{
pathname pathname
}} }}
breadcrumbRender={undefined}
onPageChange={params => { onPageChange={params => {
// navigate(params?.pathname) // navigate(params?.pathname)
}} }}
...@@ -225,9 +226,9 @@ const LayoutPage: React.FC = () => { ...@@ -225,9 +226,9 @@ const LayoutPage: React.FC = () => {
{...layoutSetting} {...layoutSetting}
menuDataRender={() => loopMenuItem(menuList)} menuDataRender={() => loopMenuItem(menuList)}
> >
<PageContainer> {/* <PageContainer> */}
<Outlet /> <Outlet />
</PageContainer> {/* </PageContainer> */}
</ProLayout> </ProLayout>
) )
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
.icon-eye { .icon-eye {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-eye.png') no-repeat; background: url('@/assets/img/icon-eye.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 0; margin: 0;
margin-right: 3px; margin-right: 3px;
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
.icon-eyes { .icon-eyes {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-eyes.png') no-repeat; background: url('@/assets/img/icon-eyes.png') no-repeat;
background-size: 100%; background-size: 100%;
cursor: pointer; cursor: pointer;
margin: 0; margin: 0;
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
.icon-save { .icon-save {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-save.png') no-repeat; background: url('@/assets/img/icon-save.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 0; margin: 0;
margin-right: 3px; margin-right: 3px;
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
.icon-set { .icon-set {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-set.png') no-repeat; background: url('@/assets/img/icon-set.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 0; margin: 0;
margin-right: 3px; margin-right: 3px;
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
.icon-list { .icon-list {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-list.png') no-repeat; background: url('@/assets/img/icon-list.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 5px 0 0 5px; margin: 5px 0 0 5px;
padding-top: 5px; padding-top: 5px;
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
.icon-right { .icon-right {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-right.png') no-repeat; background: url('@/assets/img/icon-right.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 0; margin: 0;
margin: 5px 0 0 5px; margin: 5px 0 0 5px;
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
.icon-left { .icon-left {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/icon-left.png') no-repeat; background: url('@/assets/img/icon-left.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 0; margin: 0;
margin-right: 3px; margin-right: 3px;
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
.refresh { .refresh {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: url('~@/assets/img/refresh.png') no-repeat; background: url('@/assets/img/refresh.png') no-repeat;
background-size: 100%; background-size: 100%;
margin: 5px 0 0 5px; margin: 5px 0 0 5px;
cursor: pointer; cursor: pointer;
......
import React, { useEffect, useMemo, useRef, useState } from 'react'; import React, { useEffect, useMemo, useRef, useState } from 'react'
import { Empty, Tabs } from 'antd'; import { Empty, Tabs } from 'antd'
import WebFrame from '@/pages/web_frame'; import WebFrame from '@/pages/web_frame'
import { createMicroPageUrl } from '@/utils/pub'; import { createMicroPageUrl } from '@/utils/pub'
import useVoteStore from '@/store'; import useVoteStore from '@/store/vote'
import UnitMain, { UnitMenus } from '../../UnitMain'; // 单体 import UnitMain, { UnitMenus } from '../../UnitMain' // 单体
import MergeMain, { MergeMenus } from '../../MergeMain'; // 合并 import MergeMain, { MergeMenus } from '../../MergeMain' // 合并
export type IUrlQueryType = Record<string, string>; export type IUrlQueryType = Record<string, string>
const Nav: React.FC = (props) => { const Nav: React.FC = props => {
const items = useVoteStore((state) => state.votes); const items = useVoteStore(state => state.votes)
console.log('🚀 ~ file: index.tsx:11 ~ items:', items); console.log('🚀 ~ file: index.tsx:11 ~ items:', items)
const activeKey = useVoteStore((state) => state.activeKey); const activeKey = useVoteStore(state => state.activeKey)
const setActiveKey = useVoteStore((state) => state.setActiveKey); const setActiveKey = useVoteStore(state => state.setActiveKey)
const setItems = useVoteStore((state) => state.addVotes); const setItems = useVoteStore(state => state.addVotes)
const removeItems = useVoteStore((state) => state.deleteVotes); const removeItems = useVoteStore(state => state.deleteVotes)
const newTabIndex = useRef(0); const newTabIndex = useRef(0)
const onChange = (newActiveKey: string) => { const onChange = (newActiveKey: string) => {
setActiveKey(newActiveKey); setActiveKey(newActiveKey)
}; }
const add = () => { const add = () => {
const newActiveKey = `newTab${newTabIndex.current++}`; const newActiveKey = `newTab${newTabIndex.current++}`
const newData = { label: 'New Tab', children: '', key: newActiveKey, closable: true }; const newData = { label: 'New Tab', children: '', key: newActiveKey, closable: true }
setItems({ ...newData, originData: newData }); setItems({ ...newData, originData: newData })
setActiveKey(newActiveKey); setActiveKey(newActiveKey)
}; }
const remove = (targetKey: string) => { const remove = (targetKey: string) => {
let newActiveKey = activeKey; let newActiveKey = activeKey
let lastIndex = -1; let lastIndex = -1
items.forEach((item, i) => { items.forEach((item, i) => {
if (item.key === targetKey) { if (item.key === targetKey) {
lastIndex = i - 1; lastIndex = i - 1
} }
}); })
const newPanes = items.filter((item) => item.key !== targetKey); const newPanes = items.filter(item => item.key !== targetKey)
console.log('🚀 ~ file: index.tsx:47 ~ remove ~ items:', items); console.log('🚀 ~ file: index.tsx:47 ~ remove ~ items:', items)
if (newPanes.length && newActiveKey === targetKey) { if (newPanes.length && newActiveKey === targetKey) {
if (lastIndex >= 0) { if (lastIndex >= 0) {
newActiveKey = newPanes[lastIndex].key; newActiveKey = newPanes[lastIndex].key
} else { } else {
newActiveKey = newPanes[0].key; newActiveKey = newPanes[0].key
} }
} }
removeItems(targetKey); removeItems(targetKey)
setActiveKey(newActiveKey); setActiveKey(newActiveKey)
}; }
const onEdit = (targetKey: string, action: 'add' | 'remove') => { const onEdit = (targetKey: string, action: 'add' | 'remove') => {
if (action === 'add') { if (action === 'add') {
add(); add()
} else { } else {
remove(targetKey); remove(targetKey)
} }
}; }
const creatTabPanes = () => { const creatTabPanes = () => {
return items.map((item) => { return items.map(item => {
return ( return (
<Tabs.TabPane tab={item.label} key={item.key}> <Tabs.TabPane tab={item.label} key={item.key}>
{item.url ? ( {item.url ? (
...@@ -76,9 +76,9 @@ const Nav: React.FC = (props) => { ...@@ -76,9 +76,9 @@ const Nav: React.FC = (props) => {
</div> </div>
)} )}
</Tabs.TabPane> </Tabs.TabPane>
); )
}); })
}; }
return ( return (
<div> <div>
...@@ -93,7 +93,7 @@ const Nav: React.FC = (props) => { ...@@ -93,7 +93,7 @@ const Nav: React.FC = (props) => {
{creatTabPanes()} {creatTabPanes()}
</Tabs> </Tabs>
</div> </div>
); )
}; }
export default Nav; export default Nav
This diff is collapsed.
// refer https://github.com/pmndrs/zustand
import { create } from 'zustand'
import { devtools, persist, createJSONStorage } from 'zustand/middleware'
type Store = {
votes: any[]
activeKey: any
}
type Actions = {
getActiveVote: () => any
addVotes: (vote: any) => void
deleteVotes: (key: any) => void
setActiveKey: (activeKey: any) => void
}
const voteStore = (set, get) => ({
votes: [],
activeKey: '',
getActiveVote: () => {
const votes = get().votes
const activeKey = get().activeKey
const filterArr = votes.filter(vote => vote.key === activeKey)
return filterArr.length > 0 ? filterArr[0].originData : null
},
setActiveKey: activeKey =>
set(state => ({
activeKey
})),
addVotes: vote =>
set(state => {
const existIndex = state.votes.findIndex(item => item.key === vote.key)
if (existIndex === -1) {
return { votes: [...state.votes, vote] }
}
return { votes: [...state.votes] }
}),
deleteVotes: key =>
set(state => {
const existIndex = state.votes.findIndex(item => item.key === key)
if (existIndex === -1) {
return { votes: [...state.votes] }
}
state.votes.splice(existIndex, 1)
return { votes: [...state.votes] }
})
})
const useVoteStore = create<Store & Actions & any>()(
devtools(
persist(voteStore, {
name: 'vote-storage', // name of the item in the storage (must be unique)
storage: createJSONStorage(() => sessionStorage) // (optional) by default, 'localStorage' is used
})
)
)
export default useVoteStore
This diff is collapsed.
import { defineConfig } from 'vite' import { defineConfig, type PluginOption } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
// import eslintPlugin from 'vite-plugin-eslint' // import eslintPlugin from 'vite-plugin-eslint'
// import commonjs from '@rollup/plugin-commonjs' // import commonjs from '@rollup/plugin-commonjs'
import { visualizer } from 'rollup-plugin-visualizer'
import viteImagemin from 'vite-plugin-imagemin'
// import viteCompression from 'vite-plugin-compression'
import { viteMockServe } from 'vite-plugin-mock' import { viteMockServe } from 'vite-plugin-mock'
import fs from 'fs/promises' // import fs from 'fs/promises'
import * as esbuild from 'esbuild' // import * as esbuild from 'esbuild'
import path from 'path' import path from 'path'
import proxy from './src/config/proxy' import proxy from './src/config/proxy'
const assetDir = 'assets'
const entryFileNames = `${assetDir}/js/[name]-[hash].js`
const chunkFileNames = `${assetDir}/js/[name]-[hash]-chunk.js`
const assets: any[] = [
{
output: `${assetDir}/img/[name]-[hash][extname]`,
regex: /\.(png|jpe?g|gif|svg|webp|avif)$/
},
{
regex: /\.css$/,
output: `${assetDir}/css/[name]-[hash][extname]`
},
{
output: `${assetDir}/js/[name]-[hash][extname]`,
regex: /\.js$/
},
{
output: '[name][extname]',
regex: /\.xml$/
}
]
// answer from https://stackoverflow.com/questions/74620427/how-to-configure-vite-to-allow-jsx-syntax-in-js-files // answer from https://stackoverflow.com/questions/74620427/how-to-configure-vite-to-allow-jsx-syntax-in-js-files
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({ export default defineConfig(({ command, mode }) => ({
plugins: [ plugins:
react({}), command === 'build'
// eslintPlugin({ ? [
// include: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.tsx', 'src/*.js', 'src/*.ts', 'src/*.tsx'] react({}),
// }), // eslintPlugin({
viteMockServe({ // include: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.tsx', 'src/*.js', 'src/*.ts', 'src/*.tsx']
// default // }),
localEnabled: mode === 'mock', viteMockServe({
mockPath: './mock' // default
}) localEnabled: mode === 'mock',
], mockPath: './mock'
}),
viteImagemin(),
// viteCompression(),
visualizer() as PluginOption
]
: [
react({}),
// eslintPlugin({
// include: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.tsx', 'src/*.js', 'src/*.ts', 'src/*.tsx']
// }),
viteMockServe({
// default
localEnabled: mode === 'mock',
mockPath: './mock'
})
],
optimizeDeps: { optimizeDeps: {
// force: true, //to make sure that the cache is updated // force: true, //to make sure that the cache is updated
// disabled: false // disabled: false
...@@ -62,9 +103,30 @@ export default defineConfig(({ mode }) => ({ ...@@ -62,9 +103,30 @@ export default defineConfig(({ mode }) => ({
}, },
build: { build: {
// 打包出map文件 // 打包出map文件
sourcemap: true, sourcemap: false,
commonjsOptions: { commonjsOptions: {
transformMixedEsModules: true transformMixedEsModules: true
},
minify: true,
assetsDir: assetDir,
// don't inline anything for demo
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
output: {
entryFileNames: entryFileNames,
assetFileNames: info => {
if (info && info.name) {
const name = info.name as string
const result = assets.find(a => a.regex.test(name))
if (result) {
return result.output
}
}
return `${assetDir}/[name]-[hash][extname]`
},
chunkFileNames: chunkFileNames
}
} }
} }
})) }))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment