Skip to content

Commit 8a2ba3d

Browse files
authored
chore: 升级构建工具 (#73)
* chore: 升级vite版本v4.4 * chore: 升级stylelint版本v15.10.3 * chore: 减小打包体积、优化demo体验
1 parent eb7e65e commit 8a2ba3d

File tree

49 files changed

+1679
-1145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1679
-1145
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@
9999
"editor.codeActionsOnSave": {
100100
"source.fixAll.eslint": true
101101
},
102-
"cSpell.words": ["esbuild", "pluginutils", "swipeable"]
102+
"cSpell.words": [
103+
"esbuild",
104+
"pluginutils",
105+
"postcssrc",
106+
"swipeable"
107+
]
103108
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"prettier": "^2.5.0",
3131
"pretty-quick": "^3.1.1",
3232
"rimraf": "^3.0.2",
33-
"stylelint": "^13.13.1"
33+
"stylelint": "^15.10.3"
3434
},
3535
"husky": {
3636
"hooks": {
@@ -51,7 +51,7 @@
5151
"packageManager": "pnpm@7.17.1",
5252
"pnpm": {
5353
"overrides": {
54-
"esbuild": "^0.14"
54+
"esbuild": "^0.18.11"
5555
}
5656
}
5757
}

packages/rc-cli/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@testing-library/jest-dom": "^5.15.1",
4141
"@testing-library/react": "^13.4.0",
4242
"@vant/touch-emulator": "^1.3.2",
43-
"@vitejs/plugin-react": "^2.0.1",
43+
"@vitejs/plugin-react": "^4.0.4",
4444
"address": "^1.1.2",
4545
"autoprefixer": "9.7.5",
4646
"babel-plugin-import": "^1.13.1",
@@ -51,21 +51,22 @@
5151
"commander": "^9.4.0",
5252
"consola": "^2.15.3",
5353
"conventional-changelog": "^3.1.24",
54-
"esbuild": "^0.14.54",
54+
"esbuild": "^0.18.11",
5555
"execa": "^5.1.1",
5656
"fast-glob": "^3.2.4",
5757
"front-matter": "^4.0.2",
5858
"fs-extra": "^10.1.0",
5959
"highlight.js": "^11.6.0",
6060
"jest": "^28.1.3",
6161
"jest-axe": "^6.0.1",
62-
"jest-environment-jsdom": "^28.1.3",
62+
"jest-environment-jsdom": "^29.6.2",
6363
"less": "^3.12.2",
6464
"markdown-it": "^12.0.0",
6565
"markdown-it-anchor": "^6.0.0",
6666
"ora": "^5.1.0",
6767
"postcss": "^8.1.7",
68-
"postcss-load-config": "^3.1.4",
68+
"postcss-load-config": "^4.0.1",
69+
"qrcode.react": "^3.1.0",
6970
"react-router-dom": "^6.15.0",
7071
"release-it": "^15.4.1",
7172
"rehype-highlight": "^6.0.0",
@@ -76,7 +77,7 @@
7677
"ts-node": "^9.0.0",
7778
"typescript": "^4.0.3",
7879
"vinyl-fs": "^3.0.3",
79-
"vite": "3.1.8",
80+
"vite": "^4.4.2",
8081
"vite-plugin-html": "^2.1.2"
8182
},
8283
"devDependencies": {
@@ -86,7 +87,6 @@
8687
"@types/less": "^3.0.3",
8788
"@types/markdown-it": "^12.2.3",
8889
"@types/node": "^14.11.8",
89-
"@types/postcss-load-config": "^3.0.1",
9090
"@types/react": "^18.2.20",
9191
"@types/react-router-dom": "^5.3.3",
9292
"@types/signale": "^1.4.1",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
html[data-theme='dark'] {
2+
--rc-doc-dropdown-background: #13171c;
3+
--rc-doc-icon-filter: invert(100%) sepia(94%) saturate(17%) hue-rotate(223deg) brightness(104%)
4+
contrast(98%);
5+
}
6+
7+
html {
8+
--rc-doc-dropdown-background: #fff;
9+
}
10+
11+
:root {
12+
--rc-doc-radius: 0.4rem;
13+
--rc-doc-transition-fast: 200ms;
14+
--rc-doc-transition-slow: 400ms;
15+
--rc-doc-transition-timing-default: cubic-bezier(0.08, 0.52, 0.52, 1);
16+
--rc-doc-shadow-lw: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
17+
--rc-doc-shadow-md: 0 5px 40px rgba(0, 0, 0, 0.2);
18+
--rc-doc-shadow-tl: 0 12px 28px 0 rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.1);
19+
--rc-doc-icon-arrow: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNOSA1IDUgMSAxIDUiIHN0cm9rZT0iIzAzMDYwQiIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==');
20+
--rc-doc-icon-filter: none;
21+
}
22+
23+
.doc-dropdown {
24+
--rc-doc-dropdown-offset-x: 0px;
25+
--rc-doc-dropdown-offset-y: 0px;
26+
--rc-doc-dropdown-overlay-width: 10rem;
27+
28+
position: relative;
29+
transition: opacity 0.2s ease-out;
30+
31+
* {
32+
box-sizing: border-box;
33+
}
34+
35+
&--overlay {
36+
display: inline-flex;
37+
align-items: center;
38+
&::after {
39+
content: '';
40+
font-weight: normal;
41+
background: var(--rc-doc-icon-arrow) 50%/0.5rem 0.25rem;
42+
filter: var(--rc-doc-icon-filter);
43+
background-repeat: no-repeat;
44+
border: none;
45+
min-height: 0.25rem;
46+
min-width: 0.5rem;
47+
transform: rotate(180deg);
48+
margin-left: 0.3em;
49+
}
50+
}
51+
52+
&:not(:hover) > .doc-dropdown__child {
53+
visibility: hidden;
54+
pointer-events: none;
55+
opacity: 0;
56+
transform: translate(0, -0.625rem);
57+
&.topCenter {
58+
right: 50%;
59+
transform: translate(50%, 0.625rem);
60+
}
61+
}
62+
63+
&__child {
64+
list-style: none;
65+
max-height: 80vh;
66+
min-width: var(--rc-doc-dropdown-overlay-width);
67+
opacity: 1;
68+
position: absolute;
69+
top: 100%;
70+
left: inherit;
71+
right: 0;
72+
transform: translate(0, 0);
73+
transition-property: opacity, transform, visibility;
74+
transition-duration: var(--rc-doc-transition-fast);
75+
transition-timing-function: var(--rc-doc-transition-timing-default);
76+
z-index: 100;
77+
&.topCenter {
78+
top: inherit;
79+
bottom: 100%;
80+
right: 50%;
81+
transform: translate(50%, 0);
82+
}
83+
&_content {
84+
transform: translate(var(--rc-doc-dropdown-offset-x), var(--rc-doc-dropdown-offset-y));
85+
overflow-y: auto;
86+
padding: 0.5rem;
87+
background-color: var(--rc-doc-dropdown-background);
88+
border-radius: var(--rc-doc-radius);
89+
box-shadow: var(--rc-doc-shadow-md);
90+
}
91+
}
92+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import clsx from 'classnames';
2+
import React, { CSSProperties } from 'react';
3+
import './index.less';
4+
5+
type DropdownProps = {
6+
overlay?: React.ReactNode[];
7+
arrow?: boolean;
8+
placement?: 'topCenter';
9+
offset?: [string, string];
10+
width?: CSSProperties['width'];
11+
} & React.HTMLAttributes<HTMLDivElement>;
12+
13+
const Dropdown: React.FC<DropdownProps> = ({
14+
overlay,
15+
className,
16+
children,
17+
arrow = true,
18+
placement,
19+
width,
20+
offset: [offsetX, offsetY] = ['0px', '0px'],
21+
style,
22+
...props
23+
}) => {
24+
const computedStyle = React.useMemo(() => {
25+
return {
26+
...style,
27+
'--rc-doc-dropdown-overlay-width': width,
28+
'--rc-doc-dropdown-offset-x': offsetX,
29+
'--rc-doc-dropdown-offset-y': offsetY,
30+
};
31+
}, []);
32+
return (
33+
<div
34+
className={clsx('doc-dropdown', className, {
35+
'doc-dropdown--overlay': overlay && arrow,
36+
})}
37+
style={computedStyle}
38+
{...props}
39+
>
40+
{children}
41+
{overlay && (
42+
<div className={clsx('doc-dropdown__child', placement)}>
43+
<div className="doc-dropdown__child_content">{overlay}</div>
44+
</div>
45+
)}
46+
</div>
47+
);
48+
};
49+
50+
export default Dropdown;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
3+
export default (props) => (
4+
<svg {...props} viewBox="0 0 100 100" fill="currentColor">
5+
<path d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z" />
6+
<polygon points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9" />
7+
</svg>
8+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
export default (props) => {
4+
return (
5+
<svg {...props} viewBox="0 0 1024 1024" fill="currentColor">
6+
<path d="M329.142857 658.285714l0 73.142857-73.142857 0 0-73.142857 73.142857 0zM329.142857 219.428571l0 73.142857-73.142857 0 0-73.142857 73.142857 0zM768 219.428571l0 73.142857-73.142857 0 0-73.142857 73.142857 0zM182.857143 803.986286l219.428571 0 0-218.843429-219.428571 0 0 218.843429zM182.857143 365.714286l219.428571 0 0-219.428571-219.428571 0 0 219.428571zM621.714286 365.714286l219.428571 0 0-219.428571-219.428571 0 0 219.428571zM475.428571 512l0 365.714286-365.714286 0 0-365.714286 365.714286 0zM768 804.571429l0 73.142857-73.142857 0 0-73.142857 73.142857 0zM914.285714 804.571429l0 73.142857-73.142857 0 0-73.142857 73.142857 0zM914.285714 512l0 219.428571-219.428571 0 0-73.142857-73.142857 0 0 219.428571-73.142857 0 0-365.714286 219.428571 0 0 73.142857 73.142857 0 0-73.142857 73.142857 0zM475.428571 73.142857l0 365.714286-365.714286 0 0-365.714286 365.714286 0zM914.285714 73.142857l0 365.714286-365.714286 0 0-365.714286 365.714286 0z"></path>
7+
</svg>
8+
);
9+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
export default (props) => {
4+
return (
5+
<svg {...props} viewBox="0 0 20 20" fill="currentColor">
6+
<path
7+
d="M17.875 8.313V4.374l-1.284 1.284a7.87 7.87 0 0 0-6.567-3.535 7.876 7.876 0 1 0 7.299 10.839.675.675 0 0 0-1.25-.508A6.528 6.528 0 0 1 3.497 10a6.526 6.526 0 0 1 12.116-3.364l-1.677 1.676h3.938Z"
8+
fill="currentColor"
9+
fillRule="nonzero"
10+
></path>
11+
</svg>
12+
);
13+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import HttpLink from './HttpLink';
2+
import Qrcode from './Qrcode';
3+
import Reload from './Reload';
4+
5+
export {
6+
HttpLink as HttpLinkIcon,
7+
Qrcode as QrcodeIcon,
8+
Reload as ReloadIcon,
9+
};

packages/rc-cli/site/desktop/components/Simulator/index.jsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import React, { useMemo, useEffect, useState } from 'react';
22
import classnames from 'classnames';
3-
3+
import * as Icons from '../Icons';
4+
import Dropdown from '../Dropdown';
5+
import { QRCodeCanvas } from 'qrcode.react';
46
import './index.less';
57

8+
const RCDOC_SIMULATOR_IFRAME_ID = 'rcdoc-simulator-iframe';
9+
610
const Simulator = (props) => {
711
const { src } = props;
812
const [windowHeight, setWindowHeight] = useState(0);
@@ -30,7 +34,53 @@ const Simulator = (props) => {
3034
'vant-doc-simulator-fixed': scrollTop > 60,
3135
})}
3236
>
33-
<iframe title="vant-ui-iframe" src={src} style={simulatorStyle} frameBorder="0" />
37+
<iframe
38+
id={RCDOC_SIMULATOR_IFRAME_ID}
39+
title="vant-ui-iframe"
40+
src={src}
41+
style={simulatorStyle}
42+
frameBorder="0"
43+
/>
44+
<div className="vant-doc-simulator__actions">
45+
<a
46+
className="vant-doc-simulator__actions__item"
47+
title="新窗口预览"
48+
href={src}
49+
target="_blank"
50+
>
51+
<Icons.HttpLinkIcon />
52+
</a>
53+
54+
<Dropdown
55+
offset={['0px', '-15px']}
56+
arrow={false}
57+
width={120}
58+
placement="topCenter"
59+
overlay={[
60+
<QRCodeCanvas
61+
style={{ display: 'block' }}
62+
key="qrcode"
63+
size={100}
64+
value={`${window.location.origin}${src}`}
65+
/>,
66+
]}
67+
>
68+
<Icons.QrcodeIcon className="vant-doc-simulator__actions__item" alt="手机扫二维码预览" />
69+
</Dropdown>
70+
<a
71+
className="vant-doc-simulator__actions__item"
72+
title="重新加载Demo"
73+
onClick={() => {
74+
const iframe = document.querySelector(`#${RCDOC_SIMULATOR_IFRAME_ID}`);
75+
if (iframe) {
76+
iframe.contentWindow.location.reload();
77+
}
78+
}}
79+
target="_blank"
80+
>
81+
<Icons.ReloadIcon />
82+
</a>
83+
</div>
3484
</div>
3585
);
3686
};

0 commit comments

Comments
 (0)