From e4e8b7434604ae2e3ece3d9fdf595ac714f5d1ee Mon Sep 17 00:00:00 2001 From: Simon Guo Date: Wed, 25 Dec 2024 17:56:15 +0800 Subject: [PATCH] ci: add size-limit (#517) --- .github/workflows/size-limit.yml | 24 ++++++++ package.json | 13 ++++- pnpm-lock.yaml | 99 +++++++++++++++++++++++++++++++- webpack.build.config.js | 51 ++++++++++++++++ 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/size-limit.yml create mode 100644 webpack.build.config.js diff --git a/.github/workflows/size-limit.yml b/.github/workflows/size-limit.yml new file mode 100644 index 0000000..bf83763 --- /dev/null +++ b/.github/workflows/size-limit.yml @@ -0,0 +1,24 @@ +name: Size Limit +on: + pull_request: + branches: + - main + - next + +jobs: + size: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + + - name: Install dependencies + run: npm install + + - name: Run Size Limit + run: npm run size diff --git a/package.json b/package.json index 9537f60..b2cb28d 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "format": "prettier --write \"{src,test}/**/*.{tsx,ts,js}\"", "format:check": "prettier --list-different \"{src,test}/**/*.{tsx,ts,js}\"", + "dist:pro": "webpack --mode production --progress --config webpack.build.config.js", "build": "npm run build:gulp && npm run build:types", "build:gulp": "gulp build", "build:types": "npx tsc --emitDeclarationOnly --outDir lib && npx tsc --emitDeclarationOnly --outDir es", @@ -15,6 +16,7 @@ "postbuild": "mocha test/build.test.js", "dev": "webpack serve --mode development --port 3100 --host 0.0.0.0 --progress", "publish:docs": "node docs/gh-pages.js", + "size": "npm run dist:pro && size-limit", "tdd": "cross-env NODE_ENV=test karma start", "lint:ts": "eslint src/**/*.{ts,tsx}", "lint": "npm run lint:ts", @@ -64,6 +66,7 @@ "@commitlint/cli": "^13.1.0", "@commitlint/config-conventional": "^13.1.0", "@faker-js/faker": "^7.6.0", + "@size-limit/file": "^11.1.6", "@testing-library/react": "^13.4.0", "@types/lodash": "^4.14.165", "@types/react": "^18.2.0", @@ -124,6 +127,7 @@ "rsuite": "^5.69.0", "sinon": "^19.0.2", "sinon-chai": "^3.7.0", + "size-limit": "^11.1.6", "style-loader": "^0.13.1", "ts-expect": "^1.3.0", "typescript": "^5.2.2", @@ -141,5 +145,12 @@ "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } - } + }, + "size-limit": [ + { + "path": "dist/rsuite-table.min.js", + "limit": "50 kB", + "gzip": true + } + ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd22ca2..5dd5512 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,6 +66,9 @@ importers: '@faker-js/faker': specifier: ^7.6.0 version: 7.6.0 + '@size-limit/file': + specifier: ^11.1.6 + version: 11.1.6(size-limit@11.1.6) '@testing-library/react': specifier: ^13.4.0 version: 13.4.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -246,6 +249,9 @@ importers: sinon-chai: specifier: ^3.7.0 version: 3.7.0(chai@4.5.0)(sinon@19.0.2) + size-limit: + specifier: ^11.1.6 + version: 11.1.6 style-loader: specifier: ^0.13.1 version: 0.13.2 @@ -1149,6 +1155,12 @@ packages: '@sinonjs/text-encoding@0.7.3': resolution: {integrity: sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==} + '@size-limit/file@11.1.6': + resolution: {integrity: sha512-ojzzJMrTfcSECRnaTjGy0wNIolTCRdyqZTSWG9sG5XEoXG6PNgHXDDS6gf6YNxnqb+rWfCfVe93u6aKi3wEocQ==} + engines: {node: ^18.0.0 || >=20.0.0} + peerDependencies: + size-limit: 11.1.6 + '@socket.io/component-emitter@3.1.2': resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==} @@ -1898,6 +1910,10 @@ packages: resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} engines: {node: '>=18'} + bytes-iec@3.1.1: + resolution: {integrity: sha512-fey6+4jDK7TFtFg/klGSvNKJctyU7n2aQdnM+CO0ruLPbqqMOM8Tio0Pc+deqUeVKX1tL5DQep1zQ7+37aTAsA==} + engines: {node: '>= 0.8'} + bytes@3.0.0: resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} engines: {node: '>= 0.8'} @@ -2005,6 +2021,10 @@ packages: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} engines: {node: '>= 8.10.0'} + chokidar@4.0.3: + resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} + engines: {node: '>= 14.16.0'} + chrome-trace-event@1.0.4: resolution: {integrity: sha512-rNjApaLzuwaOTjCiT8lSDdGN1APCiqkChLMJxJPWLunPAt5fy8xgU9/jNOchV84wfIxrA0lRQB7oCT8jrn/wrQ==} engines: {node: '>=6.0'} @@ -3078,6 +3098,14 @@ packages: resolution: {integrity: sha512-CzbClwlXAuiRQAlUyfqPgvPoNKTckTPGfwZV4ZdAhVcP2lh9KUxJg2b5GkE7XbjKQ3YJnQ9z6D9ntLAlB+tP8g==} engines: {node: '>=0.8.0'} + fdir@6.4.2: + resolution: {integrity: sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + figures@3.2.0: resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==} engines: {node: '>=8'} @@ -4090,6 +4118,10 @@ packages: resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==} hasBin: true + jiti@2.4.2: + resolution: {integrity: sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==} + hasBin: true + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -4293,6 +4325,10 @@ packages: resolution: {integrity: sha512-DlIPlJUkCV0Ips2zf2pJP0unEoT1kwYhiiPUGF3s/jtxTCjziNLoiVVh+jqWOWeFi6mmwQ5fNxvAUyPad4Dfog==} engines: {node: '>= 0.8'} + lilconfig@3.1.3: + resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} + engines: {node: '>=14'} + lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} @@ -4634,6 +4670,9 @@ packages: resolution: {integrity: sha512-fpoe2T0RbHwBTBUOftAfBPaDEi06ufaUai0mE6Yn1kacc3SnTErfb/h+X94VXzI64rKFHYImXSvdwGGCmwOqCA==} engines: {node: '>=0.10.0'} + nanospinner@1.2.2: + resolution: {integrity: sha512-Zt/AmG6qRU3e+WnzGGLuMCEAO/dAu45stNbHY223tUxldaDAeE+FxSPsd9Q+j+paejmm0ZbrNVs5Sraqy3dRxA==} + natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -4999,6 +5038,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pify@2.3.0: resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==} engines: {node: '>=0.10.0'} @@ -5423,6 +5466,10 @@ packages: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + readdirp@4.0.2: + resolution: {integrity: sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==} + engines: {node: '>= 14.16.0'} + rechoir@0.6.2: resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==} engines: {node: '>= 0.10'} @@ -5823,6 +5870,11 @@ packages: sinon@19.0.2: resolution: {integrity: sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g==} + size-limit@11.1.6: + resolution: {integrity: sha512-S5ux2IB8rU26xwVgMskmknGMFkieaIAqDLuwgKiypk6oa4lFsie8yFPrzRFV+yrLDY2GddjXuCaVk5PveVOHiQ==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + slash@2.0.0: resolution: {integrity: sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==} engines: {node: '>=6'} @@ -6173,6 +6225,10 @@ packages: timsort@0.3.0: resolution: {integrity: sha512-qsdtZH+vMoCARQtyod4imc2nIJwg9Cc7lPRrw9CzF8ZKR0khdr8+2nX80PBhET3tcyTtJDxAffGh2rXH4tyU8A==} + tinyglobby@0.2.10: + resolution: {integrity: sha512-Zc+8eJlFMvgatPZTl6A9L/yht8QqdmUNtURHaKZLmKBE12hNPSrqNkUp2cs3M/UKmNVVAMFQYSjYIVHDjW5zew==} + engines: {node: '>=12.0.0'} + tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} @@ -7872,6 +7928,10 @@ snapshots: '@sinonjs/text-encoding@0.7.3': {} + '@size-limit/file@11.1.6(size-limit@11.1.6)': + dependencies: + size-limit: 11.1.6 + '@socket.io/component-emitter@3.1.2': {} '@testing-library/dom@8.20.1': @@ -8767,6 +8827,8 @@ snapshots: dependencies: run-applescript: 7.0.0 + bytes-iec@3.1.1: {} + bytes@3.0.0: {} bytes@3.1.2: {} @@ -8911,6 +8973,10 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + chokidar@4.0.3: + dependencies: + readdirp: 4.0.2 + chrome-trace-event@1.0.4: {} class-utils@0.3.6: @@ -10286,6 +10352,10 @@ snapshots: dependencies: websocket-driver: 0.7.4 + fdir@6.4.2(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + figures@3.2.0: dependencies: escape-string-regexp: 1.0.5 @@ -11403,6 +11473,8 @@ snapshots: jiti@1.21.6: optional: true + jiti@2.4.2: {} + js-tokens@4.0.0: {} js-yaml@3.14.1: @@ -11645,6 +11717,8 @@ snapshots: transitivePeerDependencies: - supports-color + lilconfig@3.1.3: {} + lines-and-columns@1.2.4: {} load-json-file@1.1.0: @@ -12015,6 +12089,10 @@ snapshots: transitivePeerDependencies: - supports-color + nanospinner@1.2.2: + dependencies: + picocolors: 1.1.1 + natural-compare@1.4.0: {} needle@3.3.1: @@ -12383,6 +12461,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pify@2.3.0: {} pify@3.0.0: {} @@ -12887,6 +12967,8 @@ snapshots: dependencies: picomatch: 2.3.1 + readdirp@4.0.2: {} + rechoir@0.6.2: dependencies: resolve: 1.22.8 @@ -13364,6 +13446,16 @@ snapshots: nise: 6.1.1 supports-color: 7.2.0 + size-limit@11.1.6: + dependencies: + bytes-iec: 3.1.1 + chokidar: 4.0.3 + jiti: 2.4.2 + lilconfig: 3.1.3 + nanospinner: 1.2.2 + picocolors: 1.1.1 + tinyglobby: 0.2.10 + slash@2.0.0: {} slash@3.0.0: {} @@ -13790,6 +13882,11 @@ snapshots: timsort@0.3.0: {} + tinyglobby@0.2.10: + dependencies: + fdir: 6.4.2(picomatch@4.0.2) + picomatch: 4.0.2 + tmp@0.0.33: dependencies: os-tmpdir: 1.0.2 @@ -14015,7 +14112,7 @@ snapshots: dependencies: browserslist: 4.23.3 escalade: 3.1.2 - picocolors: 1.0.1 + picocolors: 1.1.1 update-browserslist-db@1.1.1(browserslist@4.24.3): dependencies: diff --git a/webpack.build.config.js b/webpack.build.config.js new file mode 100644 index 0000000..edd498e --- /dev/null +++ b/webpack.build.config.js @@ -0,0 +1,51 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const path = require('path'); +const webpack = require('webpack'); + +const __DEV__ = process.env.NODE_ENV === 'development'; +const filename = __DEV__ ? '[name].js' : '[name].min.js'; + +const plugins = [ + new webpack.SourceMapDevToolPlugin({ + filename: `${filename}.map` + }) +]; + +module.exports = { + entry: { + ['rsuite-table']: path.join(__dirname, 'src') + }, + output: { + path: path.join(__dirname, 'dist'), + filename, + library: 'rsuite-table', + libraryTarget: 'umd' + }, + externals: { + react: { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react' + }, + 'react-dom': { + root: 'ReactDOM', + commonjs2: 'react-dom', + commonjs: 'react-dom', + amd: 'react-dom' + } + }, + module: { + rules: [ + { + test: /\.ts|tsx?$/, + use: ['babel-loader?babelrc'], + exclude: /node_modules/ + } + ] + }, + plugins, + resolve: { + extensions: ['.ts', '.tsx', '.js'] + } +};