### Install Webpack Obfuscator Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Install the plugin with NPM and add it to your devDependencies. This plugin requires Webpack@5. ```bash npm install --save-dev javascript-obfuscator webpack-obfuscator ``` -------------------------------- ### Webpack Configuration Example Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md A complete webpack.config.js example demonstrating the plugin usage with multiple entry points and output file naming. ```javascript 'use strict'; const JavaScriptObfuscator = require('webpack-obfuscator'); module.module.exports = { entry: { 'abc': './test/input/index.js', 'cde': './test/input/index1.js' }, output: { path: 'dist', filename: '[name].js' // output: abc.js, cde.js }, plugins: [ new JavaScriptObfuscator({ rotateStringArray: true }, ['abc.js']) ] }; ``` -------------------------------- ### Configure Webpack Plugin for Pro API Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Use the WebpackObfuscator plugin with Pro API configuration for cloud-based obfuscation. Ensure javascript-obfuscator version 5.0.0 or higher is installed. ```javascript // webpack.config.js const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: './src/index.js', output: { path: __dirname + '/dist', filename: 'bundle.js' }, plugins: [ new WebpackObfuscator( // Obfuscator options { rotateStringArray: true, stringArray: true, sourceMap: true }, // Excludes ['excluded-*.js'], // Pro API configuration { apiToken: 'your-api-token-from-obfuscator.io', timeout: 300000 // 5 minutes (default) }, // Progress callback (optional) (message) => { console.log('[Obfuscation Progress]:', message); } ) ] }; // Console output during build: // [Obfuscation Progress]: Starting obfuscation... // [Obfuscation Progress]: Processing bundle.js... // [Obfuscation Progress]: Obfuscation complete ``` -------------------------------- ### Loader Usage with Pro API Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Configure the obfuscator-loader to use the Pro API for cloud-based obfuscation. Include Pro API configuration within the loader's options, along with an optional progress callback. ```javascript var WebpackObfuscator = require('webpack-obfuscator'); rules: [ { test: /\.js$/, enforce: 'post', use: { loader: WebpackObfuscator.loader, options: { rotateStringArray: true, // Pro API configuration proApiConfig: { apiToken: 'your-api-token-from-obfuscator.io', timeout: 300000 // optional }, // optional progress callback onProgress: (message) => { console.log('Obfuscation progress:', message); } } } } ] ``` -------------------------------- ### Complete Production Webpack Configuration Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt A comprehensive webpack configuration for production builds, including TerserPlugin, code splitting, DefinePlugin, and detailed webpack-obfuscator settings. Excludes vendor chunks from obfuscation for performance. ```javascript // webpack.config.js const path = require('path'); const webpack = require('webpack'); const TerserPlugin = require('terser-webpack-plugin'); const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: { 'main': './src/index.js', 'vendor': './src/vendor.js' }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].[contenthash].js', clean: true }, devtool: 'source-map', target: 'web', resolve: { extensions: ['.js', '.json'] }, optimization: { minimize: true, minimizer: [ new TerserPlugin({ terserOptions: { format: { comments: false } }, extractComments: false }) ], splitChunks: { chunks: 'all', cacheGroups: { vendor: { test: /[\/]node_modules[\/]/, name: 'vendors', chunks: 'all' } } } }, plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production'), 'process.env.API_URL': JSON.stringify('https://api.example.com') }), // Obfuscator plugin - runs after bundling new WebpackObfuscator( { // String obfuscation stringArray: true, rotateStringArray: true, stringArrayThreshold: 0.75, stringArrayEncoding: ['base64'], splitStrings: true, splitStringsChunkLength: 10, // Code transformation deadCodeInjection: true, deadCodeInjectionThreshold: 0.4, controlFlowFlattening: true, controlFlowFlatteningThreshold: 0.75, // Identifier obfuscation identifierNamesGenerator: 'hexadecimal', renameGlobals: false, // Protection features selfDefending: true, disableConsoleOutput: true, debugProtection: false, // Source maps sourceMap: true }, // Exclude vendor chunks from obfuscation for performance ['vendors*.js'] ) ] }; // npm run build output: // dist/main.abc123.js - obfuscated application code // dist/main.abc123.js.map - source map // dist/vendors.def456.js - unobfuscated vendor code (faster) // dist/vendors.def456.js.map - source map ``` -------------------------------- ### Configure Webpack Loader for Pro API Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Integrate the WebpackObfuscator loader with Pro API settings for per-file cloud obfuscation during the loading phase. Configure `proApiConfig` and `onProgress` options. ```javascript // webpack.config.js const path = require('path'); const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, module: { rules: [ { test: /\.js$/, enforce: 'post', exclude: /node_modules/, use: { loader: WebpackObfuscator.loader, options: { // Standard obfuscator options rotateStringArray: true, stringArray: true, disableConsoleOutput: true, // Pro API configuration proApiConfig: { apiToken: 'your-api-token-from-obfuscator.io', timeout: 300000 }, // Progress callback onProgress: (message) => { console.log('[Loader Progress]:', message); } } } } ] } }; ``` -------------------------------- ### Configure WebpackObfuscator Loader Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Use the WebpackObfuscator loader to obfuscate individual source files before bundling. Configure it with `enforce: 'post'` to run after other loaders like Babel and use Webpack's `exclude` option for per-file exclusions. ```javascript // webpack.config.js const path = require('path'); const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, devtool: 'source-map', module: { rules: [ // Babel loader first { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } }, // Obfuscator loader runs after Babel (enforce: 'post') { test: /\.js$/, enforce: 'post', exclude: [ path.resolve(__dirname, 'src/utils'), path.resolve(__dirname, 'src/vendor'), /node_modules/ ], use: { loader: WebpackObfuscator.loader, options: { rotateStringArray: true, stringArray: true, stringArrayThreshold: 1, disableConsoleOutput: false, sourceMap: true } } } ] } }; // Files in src/utils/ and src/vendor/ will NOT be obfuscated // All other .js files will be obfuscated before bundling ``` -------------------------------- ### TypeScript Configuration for Pro API Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Configure Webpack with TypeScript for Pro API integration, leveraging exported types for type-safe options. Set up obfuscator options, Pro API configuration, and progress callbacks. ```typescript // webpack.config.ts import * as path from 'path'; import * as webpack from 'webpack'; import WebpackObfuscator, { IProApiConfig, TProApiProgressCallback, WebpackObfuscatorOptions } from 'webpack-obfuscator'; const obfuscatorOptions: WebpackObfuscatorOptions = { rotateStringArray: true, stringArray: true, stringArrayThreshold: 0.8, deadCodeInjection: true, deadCodeInjectionThreshold: 0.4, sourceMap: true }; const proApiConfig: IProApiConfig = { apiToken: process.env.OBFUSCATOR_API_TOKEN || '', timeout: 600000 // 10 minutes for large bundles }; const onProgress: TProApiProgressCallback = (message: string): void => { console.log(`[Obfuscation] ${new Date().toISOString()}: ${message}`); }; const config: webpack.Configuration = { mode: 'production', entry: './src/index.ts', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, resolve: { extensions: ['.ts', '.js'] }, module: { rules: [ { test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/ } ] }, plugins: [ new WebpackObfuscator( obfuscatorOptions, ['vendor*.js'], proApiConfig, onProgress ) ] }; export default config; ``` -------------------------------- ### Plugin Usage with Pro API Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Integrate the WebpackObfuscator plugin with the Pro API for cloud-based obfuscation. Requires a valid API token and optionally accepts a timeout and a progress callback. ```javascript var WebpackObfuscator = require('webpack-obfuscator'); plugins: [ new WebpackObfuscator( { // obfuscator options rotateStringArray: true }, ['excluded_bundle_name.js'], // excludes { // Pro API configuration apiToken: 'your-api-token-from-obfuscator.io', timeout: 300000 // optional, request timeout in ms (default: 5 minutes) }, (message) => { // optional progress callback console.log('Obfuscation progress:', message); } ) ] ``` -------------------------------- ### Configure WebpackObfuscatorPlugin Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Use the WebpackObfuscatorPlugin to obfuscate bundled JavaScript files after compilation. Specify obfuscator options and an array of file exclusion patterns. ```javascript // webpack.config.js const path = require('path'); const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: { 'main': './src/index.js', 'vendor': './src/vendor.js', 'analytics': './src/analytics.js' }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].bundle.js' }, devtool: 'source-map', plugins: [ new WebpackObfuscator( // Obfuscator options { rotateStringArray: true, stringArray: true, stringArrayThreshold: 0.75, deadCodeInjection: true, deadCodeInjectionThreshold: 0.4, debugProtection: false, disableConsoleOutput: true, identifierNamesGenerator: 'hexadecimal', renameGlobals: false, selfDefending: true, sourceMap: true, splitStrings: true, splitStringsChunkLength: 5 }, // Excludes - files matching these patterns won't be obfuscated ['vendor*.js', 'analytics*.js'] ) ] }; // Build output: // dist/main.bundle.js - obfuscated // dist/main.bundle.js.map - source map for main // dist/vendor.bundle.js - NOT obfuscated (excluded) // dist/analytics.bundle.js - NOT obfuscated (excluded) ``` -------------------------------- ### Webpack Loader Usage Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Define a rule in your webpack config to use the obfuscator-loader. Ensure it's the last loader for your modules by using 'enforce: "post"'. ```javascript var WebpackObfuscator = require('webpack-obfuscator'); // webpack loader rules array rules: [ { test: /\.js$/, exclude: [ path.resolve(__dirname, 'excluded_file_name.js') ], enforce: 'post', use: { loader: WebpackObfuscator.loader, options: { rotateStringArray: true } } } ] ``` -------------------------------- ### Webpack Obfuscator Pro API Configuration Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Import and define TypeScript types for Webpack Obfuscator's Pro API configuration, including API token and timeout settings. A progress callback function can also be defined. ```typescript import WebpackObfuscator, { IProApiConfig, TProApiProgressCallback } from 'webpack-obfuscator'; const proApiConfig: IProApiConfig = { apiToken: 'your-token', timeout: 60000 }; const onProgress: TProApiProgressCallback = (message) => { console.log(message); }; ``` -------------------------------- ### Webpack Plugin Usage Source: https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/README.md Configure the WebpackObfuscator plugin in your webpack configuration's plugins array. You can specify obfuscator options and an array of bundle names to exclude from obfuscation. ```javascript var WebpackObfuscator = require('webpack-obfuscator'); // ... // webpack plugins array plugins: [ new WebpackObfuscator ({ rotateStringArray: true }, ['excluded_bundle_name.js']) ] ``` -------------------------------- ### Exclude Bundles from Obfuscation Source: https://context7.com/javascript-obfuscator/webpack-obfuscator/llms.txt Configure webpack-obfuscator to exclude specific bundles using multimatch glob patterns. This is useful for preventing obfuscation on vendor or polyfills. ```javascript // webpack.config.js const WebpackObfuscator = require('webpack-obfuscator'); module.exports = { mode: 'production', entry: { 'app': './src/app.js', 'admin': './src/admin.js', 'vendor': './src/vendor.js', 'polyfills': './src/polyfills.js', 'worker-main': './src/workers/main.js', 'worker-data': './src/workers/data.js' }, output: { path: __dirname + '/dist', filename: '[name].bundle.js' }, plugins: [ new WebpackObfuscator( { rotateStringArray: true, stringArray: true }, // Multimatch patterns for excludes [ 'vendor*.js', // Exclude vendor bundles 'polyfills*.js', // Exclude polyfills 'worker-*.js', // Exclude all worker bundles '**/*-excluded.js' // Exclude any file ending with -excluded.js ] ) ] }; // Result: // app.bundle.js - OBFUSCATED // admin.bundle.js - OBFUSCATED // vendor.bundle.js - not obfuscated // polyfills.bundle.js - not obfuscated // worker-main.bundle.js - not obfuscated // worker-data.bundle.js - not obfuscated ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.