Skip to content

Commit

Permalink
feat: add umd bundle to support cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
bowencool committed Apr 6, 2022
1 parent f094494 commit ccce23f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ storybook-static
coverage/
cjs/
es/
umd/
docs/
16 changes: 3 additions & 13 deletions build/rollup.config.base.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,27 +13,21 @@ 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}
*/
const config = {
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(),
],
};
Expand Down
22 changes: 22 additions & 0 deletions build/rollup.config.comps.js
Original file line number Diff line number Diff line change
@@ -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 = `/*!
Expand Down Expand Up @@ -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;
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -21,7 +21,8 @@
},
"files": [
"es",
"cjs"
"cjs",
"umd"
],
"dependencies": {
"core-js": "^3.21.1"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<a href='https://coveralls.io/github/bowencool/async-utilities?branch=main'><img src='https://coveralls.io/repos/github/bowencool/async-utilities/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://www.npmjs.com/package/high-order-async-utilities"><img src="https://img.shields.io/npm/v/high-order-async-utilities.svg?style=flat-square" alt="npm version" /></a>
<a href="https://www.npmjs.com/package/high-order-async-utilities"><img src="https://img.shields.io/npm/dt/high-order-async-utilities.svg?style=flat-square" alt="npm downloads" /></a>
<a target="_blank" rel="noopener noreferrer" href="https://npmjs.org/package/high-order-async-utilities"><img src="https://img.shields.io/npm/dm/high-order-async-utilities.svg?style=flat" alt="NPM downloads"></a>
<img src="https://img.badgesize.io/https:/unpkg.com/high-order-async-utilities/umd/index.js?label=gzip%20size&amp;compression=gzip" alt="gzip size">
<img src="https://img.shields.io/github/license/bowencool/async-utilities" alt="GitHub">
<a href="https://github.com/bowencool/create-vitepress-demo"><img src="https://img.shields.io/badge/docs%20by-vitepress-blue" alt="vitepress" /></a>
</p>

Expand All @@ -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
<script scr="//unpkg.com/high-order-async-async-utilities"></script>
<!-- or -->
<script scr="//cdn.jsdelivr.net/npm/high-order-async-async-utilities"></script>
```

# Todo

- ~~cacheAsync~~ see [memoizee](https://github.com/medikoo/memoizee#memoizing-asynchronous-functions) or [lru-pcache](https://github.com/jmendiara/lru-pcache)
Expand Down
59 changes: 55 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit ccce23f

Please sign in to comment.