Skip to content

Commit

Permalink
feat: bundle module and use package exports
Browse files Browse the repository at this point in the history
- use esbuild to bundle module in esm and cjs format
- bundle dependencies to reduce module size
- use package exports to automatically select the appropriate version
- add build step to prepublishOnly
- add build step to ci
  • Loading branch information
SomaticIT committed Jul 28, 2021
1 parent 0b02843 commit 7f36fbe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: ./coverage/coverage-final.json

- run: npm run build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ bower_components
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Compiled esbuild files
dist/

# Dependency directories
node_modules/
jspm_packages/
Expand Down
36 changes: 25 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,38 @@
"name": "fetch-blob",
"version": "3.1.2",
"description": "Blob & File implementation in Node.js, originally from node-fetch.",
"main": "index.js",
"main": "dist/esm/index.js",
"type": "module",
"files": [
"from.js",
"file.js",
"dist",
"file.d.ts",
"index.js",
"index.d.ts",
"from.d.ts",
"streams.cjs"
"from.d.ts"
],
"exports": {
".": {
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.cjs"
},
"./file": {
"import": "./dist/esm/file.mjs",
"require": "./dist/cjs/file.cjs"
},
"./from": {
"import": "./dist/esm/from.mjs",
"require": "./dist/cjs/from.cjs"
}
},
"scripts": {
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
"build:esm": "esbuild index.js --bundle --platform=node --format=esm --outfile=dist/esm/index.mjs && esbuild file.js from.js --platform=node --format=esm --outdir=dist/esm --out-extension:.js=.mjs",
"build:cjs": "esbuild index.js --bundle --platform=node --format=cjs --outfile=dist/cjs/index.cjs && esbuild file.js from.js --platform=node --format=cjs --outdir=dist/cjs --out-extension:.js=.cjs",
"build:types": "tsc --declaration --emitDeclarationOnly --allowJs index.js from.js",
"lint": "xo test.js",
"test": "npm run lint && ava",
"report": "c8 --reporter json --reporter text ava",
"coverage": "c8 --reporter json --reporter text ava && codecov -f coverage/coverage-final.json",
"prepublishOnly": "tsc --declaration --emitDeclarationOnly --allowJs index.js from.js"
"prepublishOnly": "npm run build"
},
"repository": "https://github.com/node-fetch/fetch-blob.git",
"keywords": [
Expand Down Expand Up @@ -63,8 +78,10 @@
"ava": "^3.15.0",
"c8": "^7.7.2",
"codecov": "^3.8.2",
"esbuild": "^0.12.16",
"node-fetch": "^3.0.0-beta.9",
"typescript": "^4.3.2",
"web-streams-polyfill": "^3.0.3",
"xo": "^0.40.1"
},
"funding": [
Expand All @@ -76,8 +93,5 @@
"type": "paypal",
"url": "https://paypal.me/jimmywarting"
}
],
"dependencies": {
"web-streams-polyfill": "^3.0.3"
}
]
}

0 comments on commit 7f36fbe

Please sign in to comment.