Skip to content

Commit

Permalink
build: add exports configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Oct 25, 2023
1 parent 6de173d commit bc6d65f
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 13 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ yarn add browser-dtector

or use cdn

**Minified:**

```bash
//cdn.jsdelivr.net/npm/browser-dtector@latest/browser-dtector.esm.min.js
```

**Pretty Printed:**

```bash
//cdn.jsdelivr.net/npm/browser-dtector@latest/browser-dtector.esm.js
//cdn.jsdelivr.net/npm/browser-dtector@latest/dist/browser-dtector.js
```

### Usage

This library is compiled to [UMD][umd] format, you should be able to use it in both `Node.js` and `browser`.
This library exports both ESM and CJS formats, you should be able to use it in both `Node.js` and `browser`.

```js
import BrowserDetector from 'browser-dtector';
Expand All @@ -45,7 +37,7 @@ _Note_: while using in nodejs, it is mandatory to input `useragent`.

```js
const http = require('http');
const BrowserDetector = require('browser-dtector');
const { BrowserDetector } = require('browser-dtector');

const browser = new BrowserDetector();

Expand Down Expand Up @@ -76,7 +68,7 @@ console.log('Server running at http://127.0.0.1:8080/');
<body>
Hello World!
<script type="module">
import BrowserDetector from 'https://cdn.jsdelivr.net/npm/browser-dtector/browser-dtector.esm.js';
import BrowserDetector from 'https://cdn.jsdelivr.net/npm/browser-dtector/dist/browser-dtector.js';
const detector = new BrowserDetector(window.navigator.userAgent);
console.log(detector.parseUserAgent());
Expand Down
1 change: 1 addition & 0 deletions lib/browser-dtector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ class BrowserDetector {
}
}

export { KnownBrowsers, KnownPlatforms, BrowserDetector };
export default BrowserDetector;
154 changes: 154 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@
"author": "sibiraj-s",
"license": "MIT",
"private": true,
"type": "module",
"repository": "https://github.com/sibiraj-s/browser-dtector.git",
"homepage": "https://github.com/sibiraj-s/browser-dtector#readme",
"bugs": "https://github.com/sibiraj-s/browser-dtector/issues",
"engines": {
"node": ">=16"
},
"sideEffects": false,
"files": [
"dist"
],
"main": "./dist/browser-dtector.cjs",
"module": "./dist/browser-dtector.js",
"types": "./dist/browser-dtector.d.ts",
"exports": {
".": {
"require": {
"types": "./dist/browser-dtector.d.cts",
"default": "./dist/browser-dtector.cjs"
},
"import": "./dist/browser-dtector.js",
"types": "./dist/browser-dtector.d.ts"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "tsup",
"build:docs": "vite build --base /browser-dtector/",
Expand Down Expand Up @@ -38,6 +57,7 @@
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"lint-staged": "^15.0.2",
"publint": "^0.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.17.0",
Expand Down
4 changes: 3 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export default defineConfig({
sourcemap: true,
clean: true,
outDir: 'dist',
format: ['cjs', 'esm', 'iife'],
format: ['esm', 'cjs'],
dts: true,
minify: process.env.CI === 'true',
});

0 comments on commit bc6d65f

Please sign in to comment.