-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): Add Bundle Size Page
feat(platform): Add Bundle Size Page feat(platform): Add Bundle Size Page feat(platform): Add Bundle Size Page feat(platform): Add Bundle Size Page feat(platform): Add Bundle Size Page
- Loading branch information
Showing
31 changed files
with
1,909 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rsdoctor/components': patch | ||
'@rsdoctor/client': patch | ||
--- | ||
|
||
feat(platform): report platform add bundle size page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import appTools, { defineConfig } from '@modern-js/app-tools'; | ||
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin'; | ||
|
||
const pluginName = 'Web Doctor'; | ||
|
||
export default defineConfig({ | ||
source: { | ||
entries: { | ||
main: './src/index.ts', | ||
}, | ||
}, | ||
plugins: [appTools()], | ||
builderPlugins: [ | ||
{ | ||
name: pluginName, | ||
setup(builder) { | ||
builder.modifyWebpackChain((chain) => { | ||
chain.plugin(pluginName).use(RsdoctorWebpackPlugin, [ | ||
{ | ||
disableClientServer: !process.env.ENABLE_CLIENT_SERVER, | ||
}, | ||
]); | ||
}); | ||
}, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@example/doctor-modern-minimal", | ||
"version": "0.0.1", | ||
"description": "", | ||
"files": [ | ||
"dist", | ||
"src", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"start:analysis": "ENABLE_CLIENT_SERVER=true modern start", | ||
"build:analysis": "ENABLE_CLIENT_SERVER=true modern build", | ||
"build": "modern build" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@babel/highlight": "7.18.6", | ||
"chalk": "4.1.2", | ||
"htmlparser2": "7.2.0" | ||
}, | ||
"devDependencies": { | ||
"@rsdoctor/webpack-plugin": "workspace:*", | ||
"@modern-js/app-tools": "2.41.0", | ||
"@types/node": "14.18.26", | ||
"eslint": "8.22.0", | ||
"ts-loader": "9.4.2", | ||
"tslib": "2.4.1", | ||
"typescript": "4.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Parser from 'htmlparser2'; | ||
|
||
export function getHtmlText(code: string) { | ||
let context = ''; | ||
|
||
const parser = new Parser.Parser({ | ||
ontext(data) { | ||
context += data; | ||
}, | ||
}); | ||
|
||
parser.write(code); | ||
|
||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Instance } from 'chalk'; | ||
import { highlight } from './utils'; | ||
import { getHtmlText } from './html'; | ||
|
||
const print = new Instance(); | ||
|
||
print(getHtmlText('<div>Test Text</div>')); | ||
print(highlight('const abc = 123;')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@babel/highlight'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import highlight from '@babel/highlight'; | ||
|
||
export { highlight }; | ||
export const key1 = '123'; | ||
export const key2 = '123'; | ||
|
||
console.log(key2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "@rsdoctor/tsconfig/base", | ||
"include": ["src", "webpack.config.ts"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"module": "ESNext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import React from 'react'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
|
||
import { OverallPage } from '@rsdoctor/components/pages'; | ||
import { Overall, BundleSize } from '@rsdoctor/components/pages'; | ||
|
||
|
||
export default function Router(): React.ReactElement { | ||
const routes = [ | ||
/** bundle routes */ | ||
{ | ||
path: BundleSize.route, | ||
element: <BundleSize.Page />, | ||
}, | ||
].filter((e) => Boolean(e)) as { path: string; element: JSX.Element }[]; | ||
|
||
return ( | ||
<Routes> | ||
<Route path="/" element={<OverallPage.default />} /> | ||
<Route path={OverallPage.route} element={<OverallPage.default />} /> | ||
<Route path="/" element={<Overall.Page />} /> | ||
<Route path={Overall.route} element={<Overall.Page />} /> | ||
{routes.map((e) => ( | ||
<Route key={e.path} path={e.path} element={e.element} /> | ||
))} | ||
</Routes> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { Button, Input, InputRef, Typography } from 'antd'; | ||
|
||
interface KeywordProps { | ||
style?: React.CSSProperties; | ||
labelStyle?: React.CSSProperties; | ||
icon?: React.ReactNode; | ||
label?: string; | ||
placeholder?: string; | ||
delay?: number; | ||
className?: string; | ||
width?: number; | ||
onChange: (keyword: string) => void; | ||
} | ||
|
||
export const KeywordInput: React.FC<KeywordProps> = ({ | ||
icon: Icon, | ||
label, | ||
labelStyle: ls = {}, | ||
placeholder, | ||
onChange, | ||
style, | ||
className, | ||
width, | ||
delay = 300, | ||
}) => { | ||
const labelWidth = 120; | ||
const [filename, setFilename] = useState(''); | ||
const labelStyle: React.CSSProperties = { width: labelWidth, ...ls }; | ||
|
||
const ref = useRef<InputRef>(null); | ||
|
||
let timer: NodeJS.Timeout; | ||
|
||
useEffect(() => { | ||
onChange(filename); | ||
}, [filename]); | ||
|
||
return ( | ||
<Input.Group compact style={style} className={className}> | ||
{label || Icon ? ( | ||
<Button | ||
style={labelStyle} | ||
onClick={() => { | ||
if (ref && ref.current) { | ||
ref.current.focus(); | ||
} | ||
}} | ||
> | ||
{Icon || null} | ||
<Typography.Text>{label}</Typography.Text> | ||
</Button> | ||
) : null} | ||
<Input | ||
ref={ref} | ||
allowClear | ||
defaultValue={filename} | ||
style={{ width: width ? width - labelWidth : 250 }} | ||
placeholder={placeholder} | ||
onChange={(e) => { | ||
clearTimeout(timer); | ||
const v = e.target.value.trim(); | ||
setTimeout(() => { | ||
setFilename(v); | ||
}, delay); | ||
}} | ||
/> | ||
</Input.Group> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { Typography } from 'antd'; | ||
import { TextProps } from 'antd/es/typography/Text'; | ||
|
||
export const Keyword: React.FC<TextProps & { text: string; keyword: string }> = ({ text, keyword, ...rest }) => { | ||
if (!keyword) { | ||
return <Typography.Text {...rest}>{text}</Typography.Text>; | ||
} | ||
|
||
const idx = text.indexOf(keyword); | ||
if (idx === -1) { | ||
return <Typography.Text {...rest}>{text}</Typography.Text>; | ||
} | ||
|
||
const els: (string | React.ReactNode)[] = []; | ||
|
||
let str = text; | ||
|
||
while (str.length > 0) { | ||
const idx = str.indexOf(keyword); | ||
if (idx > -1) { | ||
if (idx !== 0) { | ||
els.push( | ||
<Typography.Text key={els.length} style={{ fontSize: 'inherit' }}> | ||
{str.slice(0, idx)} | ||
</Typography.Text>, | ||
); | ||
} | ||
els.push( | ||
<Typography.Text mark key={els.length} style={{ fontSize: 'inherit' }}> | ||
{keyword} | ||
</Typography.Text>, | ||
); | ||
str = str.slice(idx + keyword.length); | ||
} else { | ||
els.push( | ||
<Typography.Text key={els.length} style={{ fontSize: 'inherit' }}> | ||
{str} | ||
</Typography.Text>, | ||
); | ||
break; | ||
} | ||
} | ||
|
||
return <Typography.Text {...rest}>{els}</Typography.Text>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.