mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
build for commonjs, esm and a standalone bundle.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,5 +2,7 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
yarn.lock
|
yarn.lock
|
||||||
package-lock.json
|
package-lock.json
|
||||||
nostr.js
|
|
||||||
.envrc
|
.envrc
|
||||||
|
standalone
|
||||||
|
cjs
|
||||||
|
esm
|
||||||
|
|||||||
29
build.cjs
29
build.cjs
@@ -2,24 +2,35 @@
|
|||||||
|
|
||||||
const esbuild = require('esbuild')
|
const esbuild = require('esbuild')
|
||||||
const alias = require('esbuild-plugin-alias')
|
const alias = require('esbuild-plugin-alias')
|
||||||
const nodeGlobals = require('@esbuild-plugins/node-globals-polyfill').default
|
|
||||||
|
|
||||||
const buildOptions = {
|
let common = {
|
||||||
entryPoints: ['index.js'],
|
entryPoints: ['index.ts'],
|
||||||
outfile: 'nostr.js',
|
|
||||||
bundle: true,
|
bundle: true,
|
||||||
format: 'esm',
|
|
||||||
plugins: [
|
plugins: [
|
||||||
alias({
|
alias({
|
||||||
stream: require.resolve('readable-stream')
|
stream: require.resolve('readable-stream')
|
||||||
}),
|
})
|
||||||
nodeGlobals({buffer: true})
|
|
||||||
],
|
],
|
||||||
define: {
|
define: {
|
||||||
window: 'self',
|
window: 'self',
|
||||||
global: 'self'
|
global: 'self'
|
||||||
},
|
},
|
||||||
loader: {'.js': 'jsx'}
|
sourcemap: 'external'
|
||||||
}
|
}
|
||||||
|
|
||||||
esbuild.build(buildOptions).then(() => console.log('build success.'))
|
esbuild
|
||||||
|
.build({...common, outdir: 'esm/', format: 'esm', packages: 'external'})
|
||||||
|
.then(() => console.log('esm build success.'))
|
||||||
|
|
||||||
|
esbuild
|
||||||
|
.build({...common, outdir: 'cjs/', format: 'cjs', packages: 'external'})
|
||||||
|
.then(() => console.log('cjs build success.'))
|
||||||
|
|
||||||
|
esbuild
|
||||||
|
.build({
|
||||||
|
...common,
|
||||||
|
outdir: 'standalone/',
|
||||||
|
format: 'iife',
|
||||||
|
globalName: 'NostrTools'
|
||||||
|
})
|
||||||
|
.then(() => console.log('standalone build success.'))
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -6,7 +6,8 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fiatjaf/nostr-tools.git"
|
"url": "https://github.com/fiatjaf/nostr-tools.git"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"main": "cjs/index.js",
|
||||||
|
"module": "esm/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/hashes": "^0.5.7",
|
"@noble/hashes": "^0.5.7",
|
||||||
"@noble/secp256k1": "^1.5.2",
|
"@noble/secp256k1": "^1.5.2",
|
||||||
@@ -25,11 +26,10 @@
|
|||||||
"nostr"
|
"nostr"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
||||||
"@types/node": "^18.0.3",
|
"@types/node": "^18.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
||||||
"@typescript-eslint/parser": "^5.46.1",
|
"@typescript-eslint/parser": "^5.46.1",
|
||||||
"esbuild": "^0.14.38",
|
"esbuild": "0.16.9",
|
||||||
"esbuild-plugin-alias": "^0.2.1",
|
"esbuild-plugin-alias": "^0.2.1",
|
||||||
"eslint": "^8.30.0",
|
"eslint": "^8.30.0",
|
||||||
"eslint-plugin-babel": "^5.3.1",
|
"eslint-plugin-babel": "^5.3.1",
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
"typescript": "^4.9.4"
|
"typescript": "^4.9.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublish": "node build.cjs",
|
"build": "node build.cjs",
|
||||||
"check-ts": "tsd && node --no-warnings --loader=esm-loader-typescript index.test-d.ts"
|
"prepublish": "yarn run build"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user