From 4e0881b347fbc503b35cb6576559cae4aa2516fa Mon Sep 17 00:00:00 2001 From: fuadop Date: Mon, 14 Feb 2022 23:24:00 +0100 Subject: [PATCH 1/4] fix: use export=Blockweave for nodejs javascript support --- src/blockweave.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/blockweave.ts b/src/blockweave.ts index 92b0fb2..d6f76f5 100644 --- a/src/blockweave.ts +++ b/src/blockweave.ts @@ -16,7 +16,7 @@ import * as blockweaveUtils from './utils/buffer'; import Logging from './utils/logging'; import Blocks from './lib/blocks'; -export default class Blockweave { +class Blockweave { public api: Api; public wallets: Wallets; public transactions: Transactions; @@ -91,3 +91,5 @@ declare global { Blockweave: typeof Blockweave; } } + +export = Blockweave; From b47d5d5a9ad150ce211a3a2ff279b1d50a1caa2b Mon Sep 17 00:00:00 2001 From: fuadop Date: Mon, 14 Feb 2022 23:25:03 +0100 Subject: [PATCH 2/4] feat: add build script for web frameworks support --- build.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/build.ts b/build.ts index 189dfa8..ad5b956 100644 --- a/build.ts +++ b/build.ts @@ -49,6 +49,32 @@ const runBuild = async () => { console.log(e); process.exit(1) }); + + // Build to frontend frameworks + build({ + plugins: [nodeBuiltIns()], + entryPoints: ['./src/blockweave.ts'], + minify: false, + bundle: true, + platform: 'browser', + target: ['es2019'], + format: 'esm', // to allow import support + splitting: true, + outdir: './web', + sourcemap: 'external', + define: { + 'process.env.NODE_DEBUG': 'false', + 'process.env.NODE_ENV': 'production', + 'process.env.DEBUG': 'false', + 'global': 'window', + 'process.cwd': 'String', + '_smartweave_1.LoggerFactory.INST': '{"create": "function() {}"}', + '__filename': 'String', + } + }).catch((e) => { + console.log(e); + process.exit(1); + }); }; runBuild(); \ No newline at end of file From 426110f6daeaa73aadc4b1fbf29ba969a5d15a2d Mon Sep 17 00:00:00 2001 From: fuadop Date: Mon, 14 Feb 2022 23:25:31 +0100 Subject: [PATCH 3/4] feat: ignore web frameworks build folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9aadc15..b856850 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,5 @@ lib # TernJS port file .tern-port + +web/ From ca6944103ca8aa27db258fbd747335dbd46fc46b Mon Sep 17 00:00:00 2001 From: fuadop Date: Mon, 14 Feb 2022 23:26:13 +0100 Subject: [PATCH 4/4] chore: add browser field, to automatically infer web build folder as main file in browser,and blockweave types --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 841f110..7f42e17 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,17 @@ "name": "blockweave", "version": "1.0.17", "main": "dist/blockweave.js", + "browser": "web/blockweave.js", + "types": "dist/blockweave.d.ts", "repository": "https://github.com/textury/blockweave.git", "author": "Cedrik ", "license": "MIT", "files": [ - "dist/**/*" + "dist", + "web" ], "scripts": { - "prebuild": "rimraf dist", + "prebuild": "rimraf dist && rimraf web", "build": "tsc && ts-node build.ts", "format": "prettier --write \"src/**/*.ts\"", "test": "npm run test:node && npm run test:web",