Compile Node.js code into bytecode.
$ npm install --save-dev little-byteCreate build/index.js
const { walker } = require('little-byte').default; const path = require('path'); walker.start({ inputDir: path.join(__dirname, '../src'), outputDir: path.join(__dirname, '../dist'), onFile(fileInfo, defaultAction) { if (fileInfo.relativePath.startsWith('foobar/')) { return 'ignore'; } if (fileInfo.ext === '.jpg') { return 'ignore'; } if (fileInfo.name === 'my-dog.txt') { return 'ignore'; } if (fileInfo.isScript) { return 'compile'; } else { // copy none-js files to dist folder return 'copy'; } } });$ node build/index.jsCreate app-entry.js
require('little-byte'); // now you can require *.bytecode require('./dist/index');The format of bytecode might change over Node.js versions.
It's possible to recover constant strings from bytecode with hex editor.
littleByte.compiler.compileFile(filePath: string, outputDir?: string): Promise<void> littleByte.loader.loadBytecode(filePath: string): vm.Script; littleByte.loader.execByteCode(filePath: string): any; type WalkAction = 'ignore' | 'compile' | 'copy'; type FileInfo = { path: string; relativePath: string; name: string; ext: string; isScript: boolean; }; interface WalkOptions { silent?: boolean; inputDir: string; outputDir: string; onFile: (fileinfo: FileInfo, defaultAction: WalkAction) => WalkAction; } littleByte.walker.start(options: WalkOptions): Promise<void>;Principles of protecting Node.js source code through bytecode
Source code and Bytecode performance test
Node.js bytecode source related issues completed
Powered By Google Translate