{"id":15297245,"url":"https://github.com/nihiue/little-byte","last_synced_at":"2025-10-26T12:03:35.831Z","repository":{"id":49377948,"uuid":"442037130","full_name":"Nihiue/little-byte","owner":"Nihiue","description":"Node.js bytecode compiler","archived":false,"fork":false,"pushed_at":"2022-09-13T06:51:36.000Z","size":64,"stargazers_count":49,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T10:18:04.306Z","etag":null,"topics":["bytecode","node-js","node-loader","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nihiue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-27T03:13:36.000Z","updated_at":"2025-03-07T11:21:45.000Z","dependencies_parsed_at":"2023-01-18T05:45:41.755Z","dependency_job_id":null,"html_url":"https://github.com/Nihiue/little-byte","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihiue%2Flittle-byte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihiue%2Flittle-byte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihiue%2Flittle-byte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nihiue%2Flittle-byte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nihiue","download_url":"https://codeload.github.com/Nihiue/little-byte/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790649,"owners_count":21162067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","node-js","node-loader","typescript"],"created_at":"2024-09-30T19:15:58.754Z","updated_at":"2025-10-26T12:03:30.795Z","avatar_url":"https://github.com/Nihiue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# little-byte\n\nCompile Node.js code into bytecode.\n\n[中文文档 | Chinese Docs](https://github.com/Nihiue/little-byte/blob/main/README.zhCN.md)\n\n![typescript](https://img.shields.io/npm/types/scrub-js.svg)\n[![npm version](https://badge.fury.io/js/little-byte.svg)](https://www.npmjs.com/package/little-byte)\n[![Test Suite](https://github.com/Nihiue/little-byte/actions/workflows/test.yaml/badge.svg)](https://github.com/Nihiue/little-byte/actions/workflows/test.yaml)\n\n## Install\n\n```bash\n$ npm install --save-dev little-byte\n```\n\n## Compile App\n\n### Prepare Build Script\n\nCreate build/index.js\n\n```javascript\nconst { walker } = require('little-byte').default;\nconst path = require('path');\n\nwalker.start({\n  inputDir: path.join(__dirname, '../src'),\n  outputDir: path.join(__dirname, '../dist'),\n  onFile(fileInfo, defaultAction) {\n    if (fileInfo.relativePath.startsWith('foobar/')) {\n      return 'ignore';\n    }\n\n    if (fileInfo.ext === '.jpg') {\n      return 'ignore';\n    }\n\n    if (fileInfo.name === 'my-dog.txt') {\n      return 'ignore';\n    }\n\n    if (fileInfo.isScript) {\n      return 'compile';\n    } else {\n      // copy none-js files to dist folder\n      return 'copy';\n    }\n  }\n});\n```\n\n### Build\n\n```bash\n$ node build/index.js\n```\n\n## Run Compiled App\n\nCreate app-entry.js\n\n```javascript\n\nrequire('little-byte');\n\n// now you can require *.bytecode\nrequire('./dist/index');\n\n```\n\n## Limitations\n\n### Using same Node.js version for building and running bytecode\n\nThe format of bytecode might change over Node.js versions.\n\n### Bytecode does not protect constant values\n\nIt's possible to recover constant strings from bytecode with hex editor.\n\n## API\n\n``` typescript\n\nlittleByte.compiler.compileFile(filePath: string, outputDir?: string): Promise\u003cvoid\u003e\n\nlittleByte.loader.loadBytecode(filePath: string): vm.Script;\n\nlittleByte.loader.execByteCode(filePath: string): any;\n\n\ntype WalkAction = 'ignore' | 'compile' | 'copy';\n\ntype FileInfo = {\n    path: string;\n    relativePath: string;\n    name: string;\n    ext: string;\n    isScript: boolean;\n};\n\ninterface WalkOptions {\n    silent?: boolean;\n    inputDir: string;\n    outputDir: string;\n    onFile: (fileinfo: FileInfo, defaultAction: WalkAction) =\u003e WalkAction;\n}\n\nlittleByte.walker.start(options: WalkOptions): Promise\u003cvoid\u003e;\n\n```\n\n## Related Articles\n\n[Principles of protecting Node.js source code through bytecode](https://translate.google.com/website?sl=auto\u0026tl=en\u0026hl\u0026u=https://zhuanlan.zhihu.com/p/359235114)\n\n[Source code and Bytecode performance test](https://github-com.translate.goog/Nihiue/little-byte-demo/blob/main/benchmark.md?_x_tr_sl=auto\u0026_x_tr_tl=en)\n\n[Node.js bytecode source related issues completed](https://translate.google.com/website?sl=auto\u0026tl=en\u0026hl\u0026u=https://zhuanlan.zhihu.com/p/419591875)\n\nPowered By Google Translate\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihiue%2Flittle-byte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnihiue%2Flittle-byte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnihiue%2Flittle-byte/lists"}