generated from sonofmagic/monorepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c19925b
commit 41edd44
Showing
11 changed files
with
864 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# weapp-fetch | ||
|
||
> 这是一个在小程序中实现 fetch 标准 api 的 npm 包 | ||
> | ||
## 为什么需要它? | ||
|
||
我想在 `weapp` 环境下,使用现代的 `graphql` 客户端,主要是 `graphql-request` 和 `@apollo/client` | ||
|
||
然而,它们都依赖于 `fetch` 这个 api,同时因为含义上传文件部分,它们也都需要 `FormData` 这样的对象 | ||
|
||
这显然在小程序这个环境下是没有的,所以,我就想着 `fork` 一下 `graphql-request` 做一个阉割版本的,在小程序环境里使用,就这样。 | ||
|
||
## Usage | ||
|
||
```js | ||
const { createFetch } = require('weapp-fetch') | ||
// cjs or esm | ||
import { createFetch } from 'weapp-fetch' | ||
// maybe you need @ts-ignore | ||
const weappFetch = createFetch(wx.request) | ||
const uniFetch = createFetch(uni.request) | ||
const taroFetch = createFetch(taro.request) | ||
|
||
weappFetch(resource) | ||
weappFetch(resource, options) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path from 'node:path' | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
// entries: ['./src/index', './src/cli'], | ||
rollup: { | ||
// 内联,相当于 nodeResolve | ||
inlineDependencies: true, | ||
// cjs | ||
emitCJS: true, | ||
// 添加 cjs 注入 | ||
cjsBridge: true, | ||
dts: { | ||
// https://github.com/unjs/unbuild/issues/135 | ||
respectExternal: false | ||
} | ||
}, | ||
alias: { | ||
// 别名 | ||
'@': path.resolve(__dirname, './src') | ||
}, | ||
// dts | ||
declaration: true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "weapp-fetch", | ||
"version": "0.0.0", | ||
"description": "fetch in weapp", | ||
"scripts": { | ||
"build": "unbuild", | ||
"test": "vitest run", | ||
"test:dev": "vitest", | ||
"release": "pnpm publish" | ||
}, | ||
"keywords": [ | ||
"weapp", | ||
"weapp-fetch", | ||
"fetch" | ||
], | ||
"author": "SonOfMagic <qq1324318532@gmail.com>", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "commonjs", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"dependencies": {} | ||
} |
Oops, something went wrong.