soranoo / next-css-obfuscator

A package deeply inspired by PostCSS-Obfuscator but for Next.js.
https://next-css-obfuscator.vercel.app
MIT License
71 stars 3 forks source link

NextJs `Compress mode` or `Minify process` is disabled when `JsAst` is enabled #19

Closed hoangnhan2ka3 closed 7 months ago

hoangnhan2ka3 commented 7 months ago

Type

Checklist

  1. [x] Updated the package to the latest version
  2. [x] Read all documentation
  3. [x] No related issue
  4. [x] Meaningful issue title (hope so...)

Environment

Describe the bug NextJs Compress mode or Minify process is disabled when enable JsAst.

To Reproduce Steps to reproduce the behavior:

Local:

  1. Turn enableJsAst to true in next-css-obfuscator.config.cjs
  2. npm run build in Terminal
  3. Check every js file in .next/static
  4. See error (not minified)

Deploy to Vercel (thru GitHub repo case):

  1. Turn enableJsAst to true in next-css-obfuscator.config.cjs
  2. Commit to GitHub
  3. After successfull deploy in Vercel, visit the website
  4. Ctrl + U or right click -> View page source
  5. Ctrl + Shift + R to hard reload
  6. Find and click a .js file in the window
  7. Ctrl + Shift + R multiple times to hard reload again (Just to be sure)
  8. See error (not minified)

Expected behavior

image

Screenshots

image

Config

module.exports = {
    enable: true, // Enable or disable the plugin.
    mode: "random", // Obfuscate mode, "random" or "simplify".
    buildFolderPath: ".next", // Build folder of your project.
    classConversionJsonFolderPath: "./css-obfuscator", // The folder path to store the before obfuscate and after obfuscated classes conversion table.
    refreshClassConversionJson: false, // Refresh the class conversion JSON file.

    classLength: 6, // Length of the obfuscated class name.
    classPrefix: "n", // Prefix of the obfuscated class name.
    classSuffix: "", // Suffix of the obfuscated class name.

    classIgnore: [
        "dark",
        "light",
        "no-transition",
        "opa-hidden",
        "big",
        "small",
        /os-scrollbar*/,
    ], // The class names to be ignored during obfuscation.

    allowExtensions: [".jsx", ".tsx", ".js", ".ts", ".html", ".rsc"], // The file extensions to be processed.

    contentIgnoreRegexes: [/\.jsxs\)\("\w+"/g], // The regexes to match the file content to be ignored during obfuscation.

    whiteListedFolderPaths: [], // Only obfuscate files in these folders

    blackListedFolderPaths: ["./.next/cache"], // Don't obfuscate files in these folders

    enableMarkers: false, // Enable or disable the obfuscate marker classes.
    markers: ["obf"], // Classes that indicate component(s) need to obfuscate.
    removeMarkersAfterObfuscated: true, // Remove the obfuscation markers from HTML elements after obfuscation.

    removeOriginalCss: true, // Delete original CSS from CSS files if it has a obfuscated version.

    generatorSeed: 84817818898, // The seed for the random generator.

    //! Experimental feature
    enableJsAst: true, // Whether to obfuscate JS files using abstract syntax tree parser (Experimental feature)

    logLevel: "info", // Log level
};

Related files

Demos (if any) N/A

Additional context I'm not sure if JsAst new mode does anything different than without it enabled, even though I've read the documentation, but maybe it's giving an error now.

hoangnhan2ka3 commented 7 months ago

However, I turned on JsAst mode a few days ago and noticed that my website's first load suddenly became slow, now I know 🐧