mirror of
https://github.com/appy-one/acebase-client.git
synced 2026-06-30 06:02:03 -06:00
dual package setup
This commit is contained in:
parent
8092250284
commit
d79905edef
3 changed files with 63 additions and 3 deletions
|
|
@ -548,6 +548,10 @@ purchase({ id: 'sword', name: 'Massive shiny sword', price: 2 })
|
|||
|
||||
```
|
||||
|
||||
## ESM and CJS bundles
|
||||
|
||||
The TypeScript sources are transpiled to both CommonJS and ESM module systems, but the CommonJS bundle is still used for both `require` and `import` statements. This prevents a possible "Dual package hazard". See https://github.com/appy-one/acebase/discussions/98 for more info.
|
||||
|
||||
## More information
|
||||
|
||||
See *acebase-server* for more information about running an AceBase server ([npm](https://www.npmjs.com/package/acebase-server), [github](https://github.com/appy-one/acebase-server))
|
||||
|
|
|
|||
37
create-package-files
Normal file
37
create-package-files
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create CommonJS package.json
|
||||
cat >dist/cjs/package.json <<JSON
|
||||
{
|
||||
"type": "commonjs",
|
||||
"browser": {
|
||||
"socket.io-client": "socket.io-client/dist/socket.io.slim.js",
|
||||
"./request/index.js": "./request/browser.js",
|
||||
"./performance/index.js": "./performance/browser.js",
|
||||
"./base64/index.js": "./base64/browser.js"
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
# Write typings to support Node16 module resolution
|
||||
cat >dist/cjs/index.d.ts <<TYPESCRIPT
|
||||
export * from '../types';
|
||||
TYPESCRIPT
|
||||
|
||||
# Create ESM package.json
|
||||
cat >dist/esm/package.json <<JSON
|
||||
{
|
||||
"type": "module",
|
||||
"browser": {
|
||||
"socket.io-client": "socket.io-client/dist/socket.io.slim.js",
|
||||
"./request/index.js": "./request/browser.js",
|
||||
"./performance/index.js": "./performance/browser.js",
|
||||
"./base64/index.js": "./base64/browser.js"
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
# Write typings to support Node16 module resolution
|
||||
cat >dist/esm/index.d.ts <<TYPESCRIPT
|
||||
export * from '../types';
|
||||
TYPESCRIPT
|
||||
25
package.json
25
package.json
|
|
@ -2,21 +2,39 @@
|
|||
"name": "acebase-client",
|
||||
"version": "1.17.2",
|
||||
"description": "Client to connect to an AceBase realtime database server",
|
||||
"comments": {
|
||||
"browser": "webpack/browserify file replacements have moved to package.json in dist/cjs and dist/esm. See README.md for more info",
|
||||
"exports": "See README.md for more info about exported and used ESM and CommonJS distributions"
|
||||
},
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/cjs/index.js",
|
||||
"require": "./dist/cjs/index.js"
|
||||
},
|
||||
"./esm": {
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/esm/index.js"
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"socket.io-client": "socket.io-client/dist/socket.io.slim.js",
|
||||
"./dist/cjs/request/index.js": "./dist/cjs/request/browser.js",
|
||||
"./dist/cjs/performance/index.js": "./dist/cjs/performance/browser.js",
|
||||
"./dist/cjs/base64/index.js": "./dist/cjs/base64/browser.js"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"private": false,
|
||||
"repository": "github:appy-one/acebase-client",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"build": "npm run build:clean && tsc && npm run browserify",
|
||||
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:packages && npm run browserify && echo Done!",
|
||||
"build:clean": "rm -fr dist/*",
|
||||
"build:esm": "tsc -p tsconfig.json && npx tsc-esm-fix ---target='dist/esm'",
|
||||
"build:cjs": "tsc -p tsconfig-cjs.json",
|
||||
"build:packages": "bash ./create-package-files",
|
||||
"browserify": "browserify dist/cjs/browser.js -o dist/browser.js --standalone acebaseclient --ignore rxjs && terser dist/browser.js -o dist/browser.min.js && cp src/browser.html dist",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"npmfix": "npm i --package-lock-only"
|
||||
|
|
@ -58,7 +76,7 @@
|
|||
"author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"acebase-core": "^1.22.4",
|
||||
"acebase-core": "file:../acebase-core",
|
||||
"socket.io-client": "^2.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -69,6 +87,7 @@
|
|||
"browserify": "^17.0.0",
|
||||
"eslint": "^8.25.0",
|
||||
"terser": "^5.15.1",
|
||||
"tsc-esm-fix": "^2.20.5",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue