From 80567f00009c8632d956a03bb1006530d854e6a4 Mon Sep 17 00:00:00 2001 From: miracles1919 Date: Mon, 24 Oct 2022 20:45:50 +0800 Subject: [PATCH] perf: build optimizations (#1936) * chore: add `@babel/plugin-transform-runtime` * perf: build optimizations * fix: ts error --- .babelrc | 19 +----- gulpfile.js | 20 ++----- package.json | 1 + packages/hooks/src/useDebounceFn/index.ts | 2 +- packages/hooks/src/useThrottleFn/index.ts | 2 +- pnpm-lock.yaml | 73 +++++++++-------------- tsconfig.json | 5 +- 7 files changed, 42 insertions(+), 80 deletions(-) diff --git a/.babelrc b/.babelrc index 643a4003db..fb0de63a02 100644 --- a/.babelrc +++ b/.babelrc @@ -1,17 +1,4 @@ { - "presets": [ - [ - "@babel/env", - { - "loose": true, - "modules": false - } - ], - "@babel/react" - ], - "include": "**/*.js", - "exclude": "**/*.ts", - "plugins": [ - "babel-plugin-transform-async-to-promises" - ] -} \ No newline at end of file + "presets": [["@babel/env"], "@babel/react"], + "plugins": ["@babel/plugin-transform-runtime"] +} diff --git a/gulpfile.js b/gulpfile.js index e7e4507ba2..740f80cf66 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,12 +10,8 @@ gulp.task('clean', async function () { }); gulp.task('cjs', function () { - const tsProject = ts.createProject('tsconfig.pro.json', { - module: 'CommonJS', - }); - return tsProject - .src() - .pipe(tsProject()) + return gulp + .src(['./es/**/*.js']) .pipe( babel({ configFile: '../../.babelrc', @@ -28,15 +24,7 @@ gulp.task('es', function () { const tsProject = ts.createProject('tsconfig.pro.json', { module: 'ESNext', }); - return tsProject - .src() - .pipe(tsProject()) - .pipe( - babel({ - configFile: '../../.babelrc', - }), - ) - .pipe(gulp.dest('es/')); + return tsProject.src().pipe(tsProject()).pipe(babel()).pipe(gulp.dest('es/')); }); gulp.task('declaration', function () { @@ -51,4 +39,4 @@ gulp.task('copyReadme', async function () { await gulp.src('../../README.md').pipe(gulp.dest('../../packages/hooks')); }); -exports.default = gulp.series('clean', 'cjs', 'es', 'declaration', 'copyReadme'); +exports.default = gulp.series('clean', 'es', 'cjs', 'declaration', 'copyReadme'); diff --git a/package.json b/package.json index d354f2226c..b8e9d0b3b8 100755 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@ant-design/icons": "^4.6.2", "@babel/cli": "^7.10.1", "@babel/core": "^7.10.2", + "@babel/plugin-transform-runtime": "^7.19.6", "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", "@testing-library/react": "^10.0.4", diff --git a/packages/hooks/src/useDebounceFn/index.ts b/packages/hooks/src/useDebounceFn/index.ts index ef50b27d2a..0728071ca6 100644 --- a/packages/hooks/src/useDebounceFn/index.ts +++ b/packages/hooks/src/useDebounceFn/index.ts @@ -6,7 +6,7 @@ import useUnmount from '../useUnmount'; import { isFunction } from '../utils'; import isDev from '../utils/isDev'; -type noop = (...args: any) => any; +type noop = (...args: any[]) => any; function useDebounceFn(fn: T, options?: DebounceOptions) { if (isDev) { diff --git a/packages/hooks/src/useThrottleFn/index.ts b/packages/hooks/src/useThrottleFn/index.ts index 7502a3b960..4575b32cf8 100644 --- a/packages/hooks/src/useThrottleFn/index.ts +++ b/packages/hooks/src/useThrottleFn/index.ts @@ -6,7 +6,7 @@ import useUnmount from '../useUnmount'; import { isFunction } from '../utils'; import isDev from '../utils/isDev'; -type noop = (...args: any) => any; +type noop = (...args: any[]) => any; function useThrottleFn(fn: T, options?: ThrottleOptions) { if (isDev) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b5b92fb5e..38dc7021b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ importers: '@ant-design/icons': ^4.6.2 '@babel/cli': ^7.10.1 '@babel/core': ^7.10.2 + '@babel/plugin-transform-runtime': ^7.19.6 '@commitlint/cli': ^17.1.2 '@commitlint/config-conventional': ^17.1.0 '@testing-library/react': ^10.0.4 @@ -57,6 +58,7 @@ importers: '@ant-design/icons': 4.7.0_wcqkhtmu7mswc6yz4uyexck3ty '@babel/cli': 7.19.3_@babel+core@7.19.3 '@babel/core': 7.19.3 + '@babel/plugin-transform-runtime': 7.19.6_@babel+core@7.19.3 '@commitlint/cli': 17.1.2 '@commitlint/config-conventional': 17.1.0 '@testing-library/react': 10.4.9_wcqkhtmu7mswc6yz4uyexck3ty @@ -1722,6 +1724,26 @@ packages: '@babel/helper-plugin-utils': 7.19.0 dev: true + /@babel/plugin-transform-runtime/7.19.6_@babel+core@7.19.3: + resolution: + { + integrity: sha512-PRH37lz4JU156lYFW1p8OxE5i7d6Sl/zV58ooyr+q1J1lnQPyg5tIiXlIwNVhJaY4W3TmOtdc8jqdXQcB1v5Yw==, + } + engines: { node: '>=6.9.0' } + peerDependencies: + '@babel/core': ^7.0.0-0 + dependencies: + '@babel/core': 7.19.3 + '@babel/helper-module-imports': 7.18.6 + '@babel/helper-plugin-utils': 7.19.0 + babel-plugin-polyfill-corejs2: 0.3.3_@babel+core@7.19.3 + babel-plugin-polyfill-corejs3: 0.6.0_@babel+core@7.19.3 + babel-plugin-polyfill-regenerator: 0.4.1_@babel+core@7.19.3 + semver: 6.3.0 + transitivePeerDependencies: + - supports-color + dev: true + /@babel/plugin-transform-shorthand-properties/7.18.6_@babel+core@7.19.3: resolution: { @@ -2803,7 +2825,7 @@ packages: dependencies: '@babel/core': 7.19.3 postcss: 7.0.39 - postcss-syntax: 0.36.2_kei4jy7wdgbhc236h4oijypxom + postcss-syntax: 0.36.2_postcss@7.0.39 transitivePeerDependencies: - supports-color dev: true @@ -2819,7 +2841,7 @@ packages: postcss-syntax: '>=0.36.2' dependencies: postcss: 7.0.39 - postcss-syntax: 0.36.2_kei4jy7wdgbhc236h4oijypxom + postcss-syntax: 0.36.2_postcss@7.0.39 remark: 13.0.0 unist-util-find-all-after: 3.0.2 transitivePeerDependencies: @@ -6797,8 +6819,8 @@ packages: engines: { node: '>=10' } hasBin: true dependencies: - is-text-path: 1.0.1 JSONStream: 1.3.5 + is-text-path: 1.0.1 lodash: 4.17.21 meow: 8.1.2 split2: 3.2.2 @@ -12113,7 +12135,7 @@ packages: pretty-format: 27.5.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.9.1_xkk4lltwku4cysulzbqoieownu + ts-node: 10.9.1_jcmx33t3olsvcxopqdljsohpme transitivePeerDependencies: - bufferutil - canvas @@ -15800,7 +15822,7 @@ packages: dependencies: htmlparser2: 3.10.1 postcss: 7.0.39 - postcss-syntax: 0.36.2_kei4jy7wdgbhc236h4oijypxom + postcss-syntax: 0.36.2_postcss@7.0.39 dev: true /postcss-image-set-function/3.0.1: @@ -16114,7 +16136,7 @@ packages: postcss: 8.4.17 dev: true - /postcss-syntax/0.36.2_kei4jy7wdgbhc236h4oijypxom: + /postcss-syntax/0.36.2_postcss@7.0.39: resolution: { integrity: sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==, @@ -16139,9 +16161,6 @@ packages: optional: true dependencies: postcss: 7.0.39 - postcss-html: 0.36.0_j55xdkkcxc32kvnyvx3y7casfm - postcss-less: 3.1.4 - postcss-scss: 2.1.1 dev: true /postcss-value-parser/4.2.0: @@ -19903,7 +19922,7 @@ packages: postcss-sass: 0.4.4 postcss-scss: 2.1.1 postcss-selector-parser: 6.0.10 - postcss-syntax: 0.36.2_kei4jy7wdgbhc236h4oijypxom + postcss-syntax: 0.36.2_postcss@7.0.39 postcss-value-parser: 4.2.0 resolve-from: 5.0.0 slash: 3.0.0 @@ -20602,40 +20621,6 @@ packages: yn: 3.1.1 dev: true - /ts-node/10.9.1_xkk4lltwku4cysulzbqoieownu: - resolution: - { - integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==, - } - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.3 - '@types/node': 18.8.4 - acorn: 8.8.0 - acorn-walk: 8.2.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 4.8.4 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - dev: true - /tslib/1.14.1: resolution: { diff --git a/tsconfig.json b/tsconfig.json index 97eba1098e..3fe88105f4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES5", + "target": "ES6", "moduleResolution": "node", "jsx": "react", "esModuleInterop": true, @@ -16,7 +16,8 @@ "allowSyntheticDefaultImports": true, "skipLibCheck": true, "declaration": false, - "strictNullChecks": true + "strictNullChecks": true, + "importHelpers": true }, "exclude": ["node_modules", "lib", "es", "dist", "example"] }