rollup.config.jsβ’3.24 kB
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import obfuscator from 'rollup-plugin-obfuscator';
import { readFileSync } from 'fs';
// Plugin to import markdown files as strings
const markdown = () => ({
name: 'markdown',
transform(_code, id) {
if (id.endsWith('.md')) {
const content = readFileSync(id, 'utf-8');
return {
code: `export default ${JSON.stringify(content)};`,
map: null
};
}
}
});
export default {
input: 'src/index.ts',
output: {
file: 'dist/index.js',
format: 'es',
sourcemap: false, // Disable source maps for production
banner: '#!/usr/bin/env node'
},
external: [
// Only externalize Node.js built-ins - users expect dependencies to be bundled
'fs', 'path', 'os', 'crypto', 'util', 'stream', 'events', 'http', 'https', 'url', 'zlib', 'buffer', 'child_process'
],
plugins: [
markdown(), // Must be first to handle .md files before TypeScript
nodeResolve({
preferBuiltins: true
}),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
sourceMap: false, // Disable source maps in TypeScript compilation
declaration: false, // No declaration files needed for executable
declarationMap: false,
noEmitOnError: true // Fail build on TypeScript errors
}),
json(),
// OBFUSCATION - Applied before minification for maximum protection
obfuscator({
// String Array Options - PRIMARY STRING HIDING
stringArray: true,
stringArrayEncoding: ['rc4'], // RC4 encryption for maximum string protection
stringArrayThreshold: 1, // Hide 100% of strings (1 = all, 0.75 = 75%)
stringArrayShuffle: true,
stringArrayRotate: true,
stringArrayWrappersCount: 2,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersType: 'function',
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 1,
// Split long strings into chunks
splitStrings: true,
splitStringsChunkLength: 10,
// Control Flow Obfuscation
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
// Dead Code Injection
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
// Identifier Obfuscation
identifierNamesGenerator: 'mangled-shuffled', // Obfuscate variable names
// Object Keys Transformation
transformObjectKeys: true,
// Number Obfuscation
numbersToExpressions: true,
// General Options
compact: true,
simplify: true,
selfDefending: true, // Anti-tampering protection
// Disable for better obfuscation with rc4
unicodeEscapeSequence: false,
// Target environment
target: 'node',
// Performance - reproducible builds
seed: 0
}),
// MINIFICATION - Applied after obfuscation
terser({
compress: {
passes: 2,
drop_console: true,
drop_debugger: true
},
format: {
comments: false
}
})
]
};