Skip to content

openwebf/node-wbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9517f60 · Jan 20, 2025
Jan 20, 2025
Apr 15, 2024
May 12, 2022
Jan 13, 2025
Sep 16, 2024
Sep 9, 2021
Sep 16, 2024
Mar 1, 2022
May 7, 2022
Apr 10, 2024
Sep 17, 2024
Apr 15, 2024
Apr 10, 2024
Feb 25, 2022
Jan 13, 2025
Apr 10, 2024
Sep 17, 2024
Sep 17, 2024

Repository files navigation

WBC

The WBC(WebF bytecode file) file generator.

The WBC file is a specially designed binary file that contains pre-compiled JavaScript bytecodes and other assets, which could speed up the loading of WebF's application.

Install

npm install @openwebf/wbc --save

Cli Usage

Install

npm install @openwebf/wbc -g

Convert JavaScript Into WBC file

wbc -s /tmp/index.js -d /tmp

Transform Inline Scripts in HTML

wbc -s ./demo.html -d ./demo_wbc.html --convert-html

Node Usage

Convert JavaScript Into WBC buffer

const { compileJavaScriptToWbc } = require('@openwebf/wbc');

compileJavaScriptToWbc('function hello() { return 1 + 1};'); // <Buffer ...> the WBC bytes

Transform Inline JavaScript Codes into WBC

const { transformInlineScriptToWbc } = require('@openwebf/wbc');

const transformedHtml = transformInlineScriptToWbc(`
<!DOCTYPE html>
<html lang="en">
<body>
    <script>
        console.log('helloworld');
    </script>
</body>
</html>
`); 

console.log(transformedHtml); /*
<html lang="en">
<body>
    <script>
    // The WBC binary contents
    </script>

</body></html>
*/

Contribute

Generate compile_commands.json

node-gyp configure -- -f gyp.generator.compile_commands_json.py

Prebuild linux binary

  1. Install docker
  2. Build local image with Dockerfile
docker build -t qjsc .
  1. Enter into images
docker run --rm -it -v $(pwd):/project qjsc
  1. Set up env in docker container
cd project
scl enable rh-nodejs12 bash
scl enable devtoolset-7 bash
  1. Build your binary
npm install
npm run prebuild