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

Build the frontend by esbuild instead of webpack #1063

Merged
merged 113 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
6bf9856
install esbuild
baurine Nov 15, 2021
c4f0493
install live-server and chokidar
baurine Nov 15, 2021
e38de03
init ui-esbuild folder
baurine Nov 16, 2021
95d254e
test compile css
baurine Nov 16, 2021
4acb3e9
compile less
baurine Nov 16, 2021
7ac21dc
test build prod
baurine Nov 16, 2021
c5e60e5
compile module less
baurine Nov 16, 2021
cc6c615
refine build
baurine Nov 16, 2021
bc8295e
test less variable
baurine Nov 16, 2021
b53c605
compile scss
baurine Nov 16, 2021
5623843
rename
baurine Nov 16, 2021
2f148fc
compile antd
baurine Nov 16, 2021
c3ac7c5
compile fluentui
baurine Nov 16, 2021
238ec57
wip
baurine Nov 17, 2021
7b4f2a1
wip
baurine Nov 17, 2021
eced827
test DatePicker
baurine Nov 17, 2021
e8863c4
compile @ant-design/icons
baurine Nov 17, 2021
d3808ee
compile svg
baurine Nov 17, 2021
450bb89
refine
baurine Nov 17, 2021
40f6167
unify builder.js
baurine Nov 17, 2021
3fef299
compile yaml
baurine Nov 17, 2021
cb9c4e8
hack postcss2
baurine Nov 17, 2021
c61ed0d
test alias paths
baurine Nov 17, 2021
588fd61
compile basic dynamic import
baurine Nov 17, 2021
fd9d8d9
compile lazy load component
baurine Nov 17, 2021
2f44161
improve dev build speed
baurine Nov 17, 2021
6536f8b
update readme
baurine Nov 17, 2021
9b64acc
refine
baurine Nov 18, 2021
e71fb87
backup original ui folder
baurine Nov 18, 2021
6db8e10
wip
baurine Nov 18, 2021
21ceaf6
remove ~ when @import antd less
baurine Nov 18, 2021
2e66a1a
try (ok)
baurine Nov 18, 2021
7248f20
pass esbuild compile
baurine Nov 18, 2021
64bb9ae
compile diagnoseReportApp
baurine Nov 19, 2021
50df3d3
remove expermental files
baurine Nov 19, 2021
85e559c
handle i18n
baurine Nov 19, 2021
8dd25cd
handle svg
baurine Nov 19, 2021
ea52d9b
handle svg as background
baurine Nov 19, 2021
ac1857a
watch more folders
baurine Nov 19, 2021
80c7312
wip - try not splitting code
baurine Nov 22, 2021
40e4422
add back less-loader
baurine Nov 23, 2021
058198b
fix primary color
baurine Nov 23, 2021
1df6a38
Merge remote-tracking branch 'refs/remotes/baurine/esbuild' into esbuild
baurine Nov 23, 2021
fe5b22a
test
baurine Nov 23, 2021
7f925ac
fix runtime crash
baurine Nov 23, 2021
1ced955
fix formatSQL crash
baurine Nov 23, 2021
0253809
handle env files
baurine Nov 24, 2021
8038644
eliminate tons of language highlight files
baurine Nov 24, 2021
b1fd304
refine copy public assets
baurine Nov 25, 2021
15ddefb
proxy diagnoseReport
baurine Nov 25, 2021
6849743
handle publicPathPrefix
baurine Nov 25, 2021
ffb18cf
handle distro
baurine Nov 25, 2021
6ac24b9
use back `build` as out dir
baurine Nov 25, 2021
2b2cc7b
refine
baurine Nov 25, 2021
5ce9796
refine gulp scripts
baurine Nov 25, 2021
9ddbedc
refine
baurine Nov 25, 2021
8c7cddd
add comments
baurine Nov 26, 2021
11f18f9
handle type check (wip)
baurine Nov 26, 2021
05c7db6
pass type check
baurine Nov 26, 2021
2202af2
check type in CI
baurine Nov 26, 2021
2d33cb5
log build time
baurine Nov 26, 2021
cfda3e8
cache postcss2 result
baurine Nov 29, 2021
5f7ad7e
fix sentry runtime crash
baurine Nov 29, 2021
ab279ca
build lib/antd.less
baurine Nov 29, 2021
45b8a2f
fix sider menu collapsed style
baurine Nov 30, 2021
0ec2eae
fix Bar component style
baurine Nov 30, 2021
987c6b3
fix BaseSelect style
baurine Dec 1, 2021
1f66bc9
make BaseSelect work again
baurine Dec 2, 2021
bd4bb5f
fix BaseSelect animation
baurine Dec 2, 2021
c1f1896
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 2, 2021
4531af1
fix yarn.lock conflicts
baurine Dec 2, 2021
b26b482
fix CI
baurine Dec 2, 2021
24989c8
upgrade node version in CI
baurine Dec 2, 2021
d5442b6
handle speedscope
baurine Dec 2, 2021
51f8959
support baseURL
baurine Dec 2, 2021
22ba497
refine
baurine Dec 2, 2021
88862b9
refine
baurine Dec 2, 2021
3b28574
refine
baurine Dec 2, 2021
30ee649
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 6, 2021
ad74c57
no need process-slim after some lib is upgraded
baurine Dec 6, 2021
c79550b
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 8, 2021
c76c449
refine process.env
baurine Dec 8, 2021
0f7749d
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 9, 2021
943ec88
use @baurine/esbuild-plugin-postcss3
baurine Dec 10, 2021
99b5b00
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 10, 2021
8007e2e
Distribution dynamic config (#2)
baurine Dec 13, 2021
87c8b79
Revert "Distribution dynamic config (#2)" (#3)
baurine Dec 13, 2021
b4af6df
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 24, 2021
12ece77
adjust for distro dynamic config
baurine Dec 24, 2021
d3a1979
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 17, 2022
8ccb6c7
update yarn.lock
baurine Jan 17, 2022
e87773b
fix `yarn build`
baurine Jan 17, 2022
781b6c3
fix `yarn tsc`
baurine Jan 17, 2022
b830bbe
refine, use autoprefixer
baurine Jan 17, 2022
6e31304
refine
baurine Jan 17, 2022
0bf0efc
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 17, 2022
79e58e2
do tsc check when dev
baurine Jan 18, 2022
18b83cb
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 18, 2022
dacb9d1
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 20, 2022
c4745fd
config eslint
baurine Jan 21, 2022
c567a10
eslint watch
baurine Jan 21, 2022
ce12e39
fix lint
baurine Jan 21, 2022
8c27ecf
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 21, 2022
0510692
fix: update cy get selector (#5)
YiniXu9506 Jan 24, 2022
472b469
fix(topsql): `react-hooks/exhaustive-deps` lint (#4)
shhdgit Jan 24, 2022
823d13d
fix lint
baurine Jan 24, 2022
090c16b
fix broken style
baurine Jan 24, 2022
aa9f33b
update cypress selector and hide code coverage temporary (#6)
YiniXu9506 Jan 24, 2022
b9cb4b7
do tsc and eslint check for production build
baurine Jan 25, 2022
7087880
remove unused code
baurine Jan 25, 2022
e33782f
revert unnecessary changes
baurine Jan 25, 2022
f6a26ba
Merge branch 'esbuild' of github.com:baurine/tidb-dashboard into esbuild
baurine Jan 25, 2022
fc9e482
fix production build
baurine Jan 25, 2022
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
9 changes: 9 additions & 0 deletions ui-esbuild/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
45 changes: 45 additions & 0 deletions ui-esbuild/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended', 'airbnb', 'prettier'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 12,
sourceType: 'module'
},
plugins: ['react', '@typescript-eslint'],
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx', '.ts', '.tsx'] }],
'import/extensions': [
'error',
'always',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never'
}
],
'no-console': 0,
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'no-use-before-define': 'off',
'no-unused-vars': 'warn',
'import/prefer-default-export': 1,
'no-shadow': 1,
'prefer-const': 1,
'prefer-spread': 1,
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }]
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
}
}
}
2 changes: 2 additions & 0 deletions ui-esbuild/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
Empty file added ui-esbuild/.husky/.gitignore
Empty file.
4 changes: 4 additions & 0 deletions ui-esbuild/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
12 changes: 12 additions & 0 deletions ui-esbuild/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"singleQuote": true,
"jsxSingleQuote": true,
"semi": false,
"tabWidth": 2,
"printWidth": 120,
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"trailingComma": "none",
"endOfLine": "auto"
}
17 changes: 17 additions & 0 deletions ui-esbuild/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# esbuild React Typescript Template

> This is a Typecript template for [esbuild create react app](https://github.com/awran5/esbuild-create-react-app) project.

## What is inside?

- [TypeScript](https://www.typescriptlang.org/)
- [esbuild](https://esbuild.github.io/)
- [Eslint](https://eslint.org/)
- [Prettier](https://prettier.io/)
- [Husky](https://github.com/typicode/husky)
- [lint-staged](https://github.com/okonet/lint-staged)
- [live-server](https://github.com/tapio/live-server)

### License

MIT © [awran5](https://github.com/awran5/)
24 changes: 24 additions & 0 deletions ui-esbuild/builder-prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { build } = require('esbuild')
const postCssPlugin = require('esbuild-plugin-postcss2').default

const buildParams = {
color: true,
entryPoints: ['src/index.tsx'],
loader: { '.ts': 'tsx' },
outdir: 'dist',
minify: true,
format: 'cjs',
bundle: true,
sourcemap: true,
logLevel: 'error',
incremental: true,
plugins: [
postCssPlugin({
lessOptions: {
javascriptEnabled: true
}
})
]
}

build(buildParams).finally(() => process.exit(0))
89 changes: 89 additions & 0 deletions ui-esbuild/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const { start } = require('live-server')
const { watch } = require('chokidar')
const { build } = require('esbuild')
const fs = require('fs')
const postCssPlugin = require('esbuild-plugin-postcss2').default

/**
* Live Server Params
* @link https://www.npmjs.com/package/live-server#usage-from-node
*/
const serverParams = {
port: 8181, // Set the server port. Defaults to 8080.
root: 'dist', // Set root directory that's being served. Defaults to cwd.
open: true // When false, it won't load your browser by default.
// host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
// ignore: 'scss,my/templates', // comma-separated string for paths to ignore
// file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
// wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec.
// mount: [['/components', './node_modules']], // Mount a directory to a route.
// logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
// middleware: [function(req, res, next) { next(); }] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack
}

const lessModifyVars = {
// '@primary-color': '#4394fc',
'@primary-color': '#1DA57A',
'@body-background': '#fff',
'@tooltip-bg': 'rgba(0, 0, 0, 0.9)',
'@tooltip-max-width': '500px'
}
const lessGlobalVars = {
'@padding-page': '48px',
'@gray-1': '#fff',
'@gray-2': '#fafafa',
'@gray-3': '#f5f5f5',
'@gray-4': '#f0f0f0',
'@gray-5': '#d9d9d9',
'@gray-6': '#bfbfbf',
'@gray-7': '#8c8c8c',
'@gray-8': '#595959',
'@gray-9': '#262626',
'@gray-10': '#000'
}

/**
* ESBuild Params
* @link https://esbuild.github.io/api/#build-api
*/
const buildParams = {
color: true,
entryPoints: ['src/index.tsx'],
loader: { '.ts': 'tsx' },
outdir: 'dist',
minify: true,
format: 'cjs',
bundle: true,
sourcemap: true,
logLevel: 'error',
incremental: true,
plugins: [
postCssPlugin({
lessOptions: {
// modifyVars: { '@primary-color': '#1DA57A' },
modifyVars: lessModifyVars,
globalVars: lessGlobalVars,
javascriptEnabled: true
}
})
]
}

async function main() {
const builder = await build(buildParams)

// TODO - refine
fs.copyFileSync('./public/index.html', './dist/index.html')
fs.copyFileSync('./public/favicon.ico', './dist/favicon.ico')
fs.copyFileSync('./public/manifest.json', './dist/manifest.json')
fs.copyFileSync('./public/logo192.png', './dist/logo192.png')
fs.copyFileSync('./public/logo512.png', './dist/logo512.png')
baurine marked this conversation as resolved.
Show resolved Hide resolved

watch('src/**/*').on('all', () => {
builder.rebuild()
})

start(serverParams)
}

main()
50 changes: 50 additions & 0 deletions ui-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "tidb-dashboard-ui",
"version": "0.1.0",
"private": true,
"scripts": {
"pre-commit": "lint-staged",
"lint": "eslint \"src/**/*.{ts,tsx}\" --max-warnings=0",
"start": "node builder.js",
"build": "esbuild src/index.tsx --minify --format=cjs --outdir=public --sourcemap --bundle",
"prod": "node builder-prod.js"
},
"dependencies": {
"antd": "^4.16.13",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/live-server": "^1.2.1",
"@types/node": "^16.9.1",
"@types/react": "^17.0.20",
"@types/react-dom": "^17.0.9",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"chokidar": "^3.5.2",
"esbuild": "^0.12.26",
"esbuild-plugin-postcss2": "^0.1.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.25.1",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.2",
"less": "^4.1.2",
"lint-staged": "^11.1.2",
"live-server": "^1.2.1",
"prettier": "^2.4.0",
"typescript": "^4.4.3"
},
"lint-staged": {
"*.+(js|jsx)": "eslint --fix",
"*.+(json|css|md)": "prettier --write"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
Binary file added ui-esbuild/public/favicon.ico
Binary file not shown.
26 changes: 26 additions & 0 deletions ui-esbuild/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/jpg" href="favicon.ico" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using react-esbuild-app" />
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="manifest.json" />
<title>React ESBuild</title>
<link rel="stylesheet" href="index.css">
</head>

<body>
<div id="root"></div>
<script src="index.js"></script>
</body>

</html>
Binary file added ui-esbuild/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui-esbuild/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions ui-esbuild/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "React esbuild App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions ui-esbuild/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
20 changes: 20 additions & 0 deletions ui-esbuild/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import './style.less'

import HelloCSS from './lib/test-components/HelloCSS'
import HelloLess from './lib/test-components/HelloLess'
import HelloMLess from './lib/test-components/HelloModuleLess'
import HelloSCSS from './lib/test-components/HelloSCSS'
import HelloAntD from './lib/test-components/HelloAntD'

export default function App() {
return (
<div>
<HelloCSS />
<HelloLess />
<HelloMLess />
<HelloSCSS />
<HelloAntD />
</div>
)
}
5 changes: 5 additions & 0 deletions ui-esbuild/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

ReactDOM.render(<App />, document.getElementById('root'))
15 changes: 15 additions & 0 deletions ui-esbuild/src/lib/test-components/HelloAntD/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import styles from './style.module.less'

import { Button, Switch, Space } from 'antd'

export default function HelloAntD() {
return (
<div className={styles['hello-antd-container']}>
<Space>
<Button>Hello Antd</Button>
<Switch />
</Space>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.hello-antd-container {
text-align: center;
padding: 8px;
}
10 changes: 10 additions & 0 deletions ui-esbuild/src/lib/test-components/HelloCSS/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import './style.css'

export default function HelloCSS() {
return (
<div className='hello-css-container'>
<h1>HelloCSS</h1>
</div>
)
}
7 changes: 7 additions & 0 deletions ui-esbuild/src/lib/test-components/HelloCSS/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.hello-css-container {
text-align: center;
}

.hello-css-container h1 {
color: skyblue;
}
10 changes: 10 additions & 0 deletions ui-esbuild/src/lib/test-components/HelloLess/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import './style.less'

export default function HelloLess() {
return (
<div className='hello-less-container'>
<h1>HelloLess</h1>
</div>
)
}
Loading