This is an example project showing how H5 (A modern Bridge.net fork) can be used to write modules for Node/TS rather than just building index.html and web-apps. It demonstrates how to share logic between C# and TypeScript projects.
It may seem simple, but as someone who is new to this and was struggling for the last day on this, I hope this repo helps someone in future!
TL;DR: You can just ignore index.html and require the .js files directly, pretty much!
- Node.js
- TypeScript
- H5
- .NET SDK
-
Clone the repository:
git clone https://github.com/daireb/ExampleH5Project.git cd ExampleH5Project -
Install the dependencies:
npm install
To compile from C# to JS/TS, run the following command:
dotnet build
To run the project, execute the TypeScript or JavaScript files as normal:
node src/test.js
or
npx ts-node src/test.ts
The main logic is in SharedLogic.cs, which compiles into the /dist folder. The logic can then be accessed as shown in test.js and test.ts.
It's important to require the h5.js file before the shared logic, as it sets up the H5 environment.
require(`../dist/h5.js`);
require(`../dist/MySharedLogic.js`);
// Rest of your script/// <reference path="../dist/MySharedLogic.d.ts" />
require(`../dist/h5.js`);
require(`../dist/MySharedLogic.js`);
// Rest of your script