esbuild-obfuscator-plugin is an elegant and powerful JavaScript obfuscator plugin for esbuild, powered by javascript-obfuscator.
npm install esbuild-obfuscator-pluginInstall using your favorite package manager
pnpm
pnpm install esbuild-obfuscator-pluginyarn
yarn add esbuild-obfuscator-pluginAutomatically 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 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,
}),
],
});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,
}),
],
});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,
}),
],
});For all obfuscation options, please see the javascript-obfuscator documentation.
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! 🙏
MIT © Shahrad Elahi and contributors.