From ccce23fd7dc047b6fad1cef3469a69b1682aa245 Mon Sep 17 00:00:00 2001 From: Bowen Date: Wed, 6 Apr 2022 10:50:00 +0800 Subject: [PATCH] feat: add umd bundle to support cdn --- .gitignore | 1 + build/rollup.config.base.js | 16 ++-------- build/rollup.config.comps.js | 22 ++++++++++++++ package.json | 10 ++++-- readme.md | 15 ++++++++- yarn.lock | 59 +++++++++++++++++++++++++++++++++--- 6 files changed, 102 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 71ed197..a8796cd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ storybook-static coverage/ cjs/ es/ +umd/ docs/ diff --git a/build/rollup.config.base.js b/build/rollup.config.base.js index 5858d00..db51f00 100644 --- a/build/rollup.config.base.js +++ b/build/rollup.config.base.js @@ -1,10 +1,6 @@ -// import esbuild from 'rollup-plugin-esbuild'; import { resolve } from 'path'; -import vue from 'rollup-plugin-vue'; // 处理vue文件 import babel from '@rollup/plugin-babel'; import typescript from 'rollup-plugin-typescript2'; -import postcss from 'rollup-plugin-postcss'; -// import styles from 'rollup-plugin-styles'; import replace from '@rollup/plugin-replace'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import pkg from '../package.json'; @@ -17,7 +13,7 @@ const deps = Object.keys(pkg.peerDependencies || {}) .concat(Object.keys(pkg.devDependencies)) .concat([/node_modules/]); -const genBaseConfig = ({ ts } = {}) => { +const genBaseConfig = ({ ts, plugins = [] } = {}) => { /** * @type {import('rollup').RollupOptions} */ @@ -25,19 +21,13 @@ const genBaseConfig = ({ ts } = {}) => { external: deps, plugins: [ replace({ values: replacement, preventAssignment: true }), - // vue({ - // exposeFilename: true, - // // preprocessStyles: true, - // }), - // postcss({ - // extract: true, - // }), typescript({ ...ts, tsconfig: resolve(__dirname, '../tsconfig.build.json') }), babel({ babelHelpers: 'runtime', skipPreflightCheck: true, - extensions: ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.vue'], + extensions: ['.js', '.mjs', '.jsx', '.ts', '.tsx'], }), + ...plugins, nodeResolve(), ], }; diff --git a/build/rollup.config.comps.js b/build/rollup.config.comps.js index 87f2b85..99802dd 100644 --- a/build/rollup.config.comps.js +++ b/build/rollup.config.comps.js @@ -1,5 +1,6 @@ import { defineConfig } from 'rollup'; import genBaseConfig, { INPUT_PATH } from './rollup.config.base'; +import { terser } from 'rollup-plugin-terser'; const name = 'asyncUtilities'; const banner = `/*! @@ -37,6 +38,27 @@ const componentsConfig = defineConfig([ }, ], }, + { + ...genBaseConfig({ + plugins: [terser()], + // ts: { + // useTsconfigDeclarationDir: false, + // compilerOptions: { + // declaration: false, + // }, + // }, + }), + input: `${INPUT_PATH}/index.ts`, + output: [ + { + dir: 'umd', + format: 'umd', + sourcemap: true, + banner, + name, + }, + ], + }, ]); export default componentsConfig; diff --git a/package.json b/package.json index 10ab17d..9f682b5 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build:demos": "vite build -c=website/.vitepress/markdown/plugin/build-demos.vite.config.ts", "predev": "check-versions && ([ -d es ] || npm run build) && patch-package", "test": "jest --coverage", - "prebuild": "check-versions && rm -rf es cjs && patch-package", + "prebuild": "check-versions && rm -rf es cjs umd && patch-package", "prebuild:docs": "npm run build && patch-package", "postbuild:docs": "rm -rf docs/ && mv website/.vitepress/dist/ docs/", "preversion": "scripts/check-version-bump.js", @@ -21,7 +21,8 @@ }, "files": [ "es", - "cjs" + "cjs", + "umd" ], "dependencies": { "core-js": "^3.21.1" @@ -52,7 +53,6 @@ "check-versions-in-packagejson": "^1.2.5", "conventional-changelog-cli": "^2.1.1", "copy-rich-text": "^0.2.0", - "core-js": "^3.20.0", "coveralls": "^3.1.1", "dayjs": "^1.11.0", "fs-extra": "^10.0.1", @@ -67,7 +67,9 @@ "postcss": "^8.4.12", "prettier": "^2.6.0", "rollup": "^2.61.1", + "rollup-plugin-esbuild": "^4.8.2", "rollup-plugin-postcss": "^4.0.2", + "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.31.1", "rollup-plugin-vue": "^6.0.0", "sass": "^1.49.9", @@ -88,6 +90,8 @@ "peerDependencies": {}, "main": "cjs/index.js", "module": "es/index.js", + "unpkg": "umd/index.js", + "jsdelivr": "umd/index.js", "typings": "es/index.d.ts", "license": "MIT", "homepage": "https://github.com/bowencool/async-utilities", diff --git a/readme.md b/readme.md index 7b8a072..dcb4c58 100644 --- a/readme.md +++ b/readme.md @@ -5,6 +5,9 @@ Coverage Status npm version npm downloads + NPM downloads + gzip size + GitHub vitepress

@@ -14,14 +17,24 @@ An asynchronous tool library in the style of higher-order functions. [Website](h # Usage +使用 npm: + ```bash -yarn add high-order-async-utilities +npm i high-order-async-utilities ``` ```ts import { throttleAsyncResult } from 'high-order-async-utilities'; ``` +在浏览器中: + +```html + + + +``` + # Todo - ~~cacheAsync~~ see [memoizee](https://github.com/medikoo/memoizee#memoizing-asynchronous-functions) or [lru-pcache](https://github.com/jmendiara/lru-pcache) diff --git a/yarn.lock b/yarn.lock index 4591278..95b4d8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -146,7 +146,7 @@ dependencies: "@babel/highlight" "^7.10.4" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.14.5", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.8.3": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.14.5", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.8.3": version "7.16.7" resolved "https://registry.npmmirror.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789" integrity sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg== @@ -1696,6 +1696,14 @@ estree-walker "^1.0.1" picomatch "^2.2.2" +"@rollup/pluginutils@^4.1.1": + version "4.2.0" + resolved "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.0.tgz#a14bbd058fdbba0a5647143b16ed0d86fb60bd08" + integrity sha512-2WUyJNRkyH5p487pGnn4tWAsxhEFKN/pT8CMgHshd5H+IXkOnKvKZwsz5ZWz+YCXkleZRAU5kwbfgF8CPfDRqA== + dependencies: + estree-walker "^2.0.1" + picomatch "^2.2.2" + "@rollup/pluginutils@^4.1.2": version "4.1.2" resolved "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-4.1.2.tgz#ed5821c15e5e05e32816f5fb9ec607cdf5a75751" @@ -2412,7 +2420,7 @@ acorn@^7.1.1, acorn@^7.4.0: resolved "https://registry.npmmirror.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== -acorn@^8.2.4, acorn@^8.4.1: +acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0: version "8.7.0" resolved "https://registry.npmmirror.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== @@ -3865,7 +3873,7 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es-module-lexer@^0.9.0: +es-module-lexer@^0.9.0, es-module-lexer@^0.9.3: version "0.9.3" resolved "https://registry.npmmirror.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== @@ -5651,7 +5659,7 @@ jest-watcher@^26.6.2: jest-util "^26.6.2" string-length "^4.0.1" -jest-worker@^26.6.2: +jest-worker@^26.2.1, jest-worker@^26.6.2: version "26.6.2" resolved "https://registry.npmmirror.com/jest-worker/-/jest-worker-26.6.2.tgz#7f72cbc4d643c365e27b9fd775f9d0eaa9c7a8ed" integrity sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ== @@ -5678,6 +5686,11 @@ jest@26: import-local "^3.0.2" jest-cli "^26.6.3" +joycon@^3.0.1: + version "3.1.1" + resolved "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz#bce8596d6ae808f8b68168f5fc69280996894f03" + integrity sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw== + js-stringify@^1.0.2: version "1.0.2" resolved "https://registry.npmmirror.com/js-stringify/-/js-stringify-1.0.2.tgz#1736fddfd9724f28a3682adc6230ae7e4e9679db" @@ -7630,6 +7643,17 @@ rimraf@^3.0.0, rimraf@^3.0.2: dependencies: glob "^7.1.3" +rollup-plugin-esbuild@^4.8.2: + version "4.8.2" + resolved "https://registry.npmjs.org/rollup-plugin-esbuild/-/rollup-plugin-esbuild-4.8.2.tgz#c097b93cd4b622e62206cadb5797589f548cf48c" + integrity sha512-wsaYNOjzTb6dN1qCIZsMZ7Q0LWiPJklYs2TDI8vJA2LUbvtPUY+17TC8C0vSat3jPMInfR9XWKdA7ttuwkjsGQ== + dependencies: + "@rollup/pluginutils" "^4.1.1" + debug "^4.3.3" + es-module-lexer "^0.9.3" + joycon "^3.0.1" + jsonc-parser "^3.0.0" + rollup-plugin-postcss@^4.0.2: version "4.0.2" resolved "https://registry.npmmirror.com/rollup-plugin-postcss/-/rollup-plugin-postcss-4.0.2.tgz#15e9462f39475059b368ce0e49c800fa4b1f7050" @@ -7649,6 +7673,16 @@ rollup-plugin-postcss@^4.0.2: safe-identifier "^0.4.2" style-inject "^0.3.0" +rollup-plugin-terser@^7.0.2: + version "7.0.2" + resolved "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" + integrity sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ== + dependencies: + "@babel/code-frame" "^7.10.4" + jest-worker "^26.2.1" + serialize-javascript "^4.0.0" + terser "^5.0.0" + rollup-plugin-typescript2@^0.31.1: version "0.31.2" resolved "https://registry.npmmirror.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.31.2.tgz#463aa713a7e2bf85b92860094b9f7fb274c5a4d8" @@ -7794,6 +7828,13 @@ semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0: resolved "https://registry.npmmirror.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== +serialize-javascript@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa" + integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw== + dependencies: + randombytes "^2.1.0" + serialize-javascript@^6.0.0: version "6.0.0" resolved "https://registry.npmmirror.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" @@ -8315,6 +8356,16 @@ terser-webpack-plugin@^5.1.3: source-map "^0.6.1" terser "^5.7.2" +terser@^5.0.0: + version "5.12.1" + resolved "https://registry.npmjs.org/terser/-/terser-5.12.1.tgz#4cf2ebed1f5bceef5c83b9f60104ac4a78b49e9c" + integrity sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ== + dependencies: + acorn "^8.5.0" + commander "^2.20.0" + source-map "~0.7.2" + source-map-support "~0.5.20" + terser@^5.7.2: version "5.10.0" resolved "https://registry.npmmirror.com/terser/-/terser-5.10.0.tgz#b86390809c0389105eb0a0b62397563096ddafcc"