Licence
MIT
Version
1.0.1
Deps
2
Size
14 kB
Vulns
0
Weekly
0
esbuild-obfuscator-plugin
esbuild-obfuscator-plugin is an elegant and powerful JavaScript obfuscator plugin for esbuild, powered by javascript-obfuscator.
Installation
npm install esbuild-obfuscator-pluginInstall using your favorite package manager
pnpm
pnpm install esbuild-obfuscator-pluginyarn
yarn add esbuild-obfuscator-pluginUsage
Basic Usage
Automatically obfuscate source files matching JavaScript and TypeScript extensions.
import esbuild from 'esbuild';
import ObfuscatorPlugin from 'esbuild-obfuscator-plugin';
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
plugins: [
ObfuscatorPlugin({
compact: true,
controlFlowFlattening: true,
}),
],
});Obfuscate Output Files
Obfuscate generated output files on build completion instead of source files.
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
plugins: [
ObfuscatorPlugin({
obfuscateOutput: true,
compact: true,
}),
],
});File Filtering
Limit obfuscation to specific files using glob patterns or a custom function.
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
plugins: [
ObfuscatorPlugin({
filter: ['**/src/secret/**/*', '**/utils.ts'],
compact: true,
}),
],
});Using a custom function:
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
plugins: [
ObfuscatorPlugin({
filter: (path) => path.endsWith('.ts'),
compact: true,
}),
],
});Code Injection
Inject additional code headers or banners into specific files.
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
plugins: [
ObfuscatorPlugin({
inject: {
'**/index.ts': ['console.log("Injected header statement!");'],
},
compact: true,
}),
],
});Documentation
For all obfuscation options, please see the javascript-obfuscator documentation.
Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated!
License
MIT Shahrad Elahi and contributors.