Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

Protect the module that holds your logic, not the vendor code around it

When teams first add an obfuscator, the default move is to feed it the entire production bundle. It feels thorough. In practice it often means you spend most of your runtime and file-size budget protecting React, a date

When teams first add an obfuscator, the default move is to feed it the entire production bundle. It feels thorough. In practice it often means you spend most of your runtime and file-size budget protecting React, a date library, and a polyfill that anyone can download from npm in readable form.

Disclosure up front: I help promote MeowShield, a JavaScript obfuscation tool. The scoping approach below works with any obfuscator; I'll use MeowShield's terms where they're relevant.

Ask what is actually yours

Open your bundle analyzer (rollup-plugin-visualizer, webpack-bundle-analyzer, or source-map-explorer) and sort by size. For a typical single-page app you'll see something like:

  • framework and router code
  • UI component libraries
  • utility libraries (dates, validation, i18n)
  • your own code, often a fraction of the total

Only the last group contains something a competitor can't already get. Obfuscating public open-source code buys almost nothing: the readable original is one npm install away.

Split the bundle so the valuable part is its own file

Most bundlers make this easy. With Vite or Rollup, manualChunks can put vendor code in a separate chunk:

// vite.config.js
export default {
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) return "vendor";
          if (id.includes("/src/pricing-engine/")) return "core-logic";
        }
      }
    }
  }
};

Now your pipeline produces vendor-[hash].js and core-logic-[hash].js. Protect core-logic, leave vendor minified only.

Why this pays off

Runtime cost lands where it matters. Stronger protection generally means more work at runtime. MeowShield's docs describe Low as compatibility-first, Medium as stronger control-flow protection with moderate cost, and High as VM-oriented protection for critical business logic. Applying High to a whole bundle is very different from applying it to one small module. Scoping lets you choose a stronger level for the small piece that deserves it.

Compatibility issues shrink. Framework internals sometimes depend on top-level names, Function.prototype.toString, or precise global behavior. Leaving them untouched removes a whole class of "it worked before obfuscation" bugs. (MeowShield's KeepTopVar option exists for this reason and is ON by default in Low.)

Debugging stays sane. Stack traces from vendor frames remain readable, so you can tell quickly whether a crash is in your protected module or in a library.

License notices stay intact. Many open-source licenses require you to keep a copyright notice with the code. Not running vendor code through an obfuscator makes that easy to honor.

Watch the boundary

When you split, the protected module talks to the rest of the app through imports and exports. Keep that surface small and boring: plain functions with clear inputs and outputs. If the public interface leaks the entire algorithm through function names and arguments, obfuscating the body won't help much. And as always, anything security-critical (entitlements, prices, permissions) still has to be enforced on the server.

A sensible workflow

  1. Analyze the bundle and list the modules that are genuinely proprietary.
  2. Isolate them into their own chunk.
  3. Run that chunk through the smallest MeowShield level that matches your threat model, then compare runtime behavior and size against the unprotected chunk.
  4. Raise the level for that chunk only if the measurements allow it.

You can try step 3 with a single chunk in the MeowShield Playground: https://meowshield.com/?utm_source=devto&utm_medium=post&utm_campaign=protect-your-logic-not-vendor-code. Start with Low, then compare.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.