Skip to content

Commit

Permalink
feat: universal + isomorphic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 9, 2020
1 parent 7764d41 commit a873702
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ yarn add ohmyfetch
Import:

```js
// Browser / Workers
import { $fetch } from 'ohmyfetch/browser'
// Universal (requires global.fetch)
import { $fetch } from 'ohmyfetch'

// NodeJS
// NodeJS / Isomorphic
import { $fetch } from 'ohmyfetch/node'

// NodeJS (commonjs)
// NodeJS / Isomorphic (CommonJS)
const { $fetch } = require('ohmyfetch/node')
```

Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
"node": {
"import": "./node.mjs",
"require": "./node.js"
},
"browser": {
"import": "./browser.mjs",
"require": "./browser.js"
}
},
"main": "./dist/node.js",
"module": "./dist/node.mjs",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
Expand Down
7 changes: 0 additions & 7 deletions src/browser.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createFetch } from './base'

export * from './base'

// ref: https://github.com/tc39/proposal-global
const getGlobal = function () {
if (typeof self !== 'undefined') { return self }
if (typeof window !== 'undefined') { return window }
if (typeof global !== 'undefined') { return global }
throw new Error('unable to locate global object')
}

export const $fetch = createFetch({
fetch: getGlobal().fetch || (() => {
return Promise.reject(new Error('[ohmyfetch] global.fetch is not supported!'))
})
})

0 comments on commit a873702

Please sign in to comment.