getkey / rollup-plugin-obfuscator

The most powerful rollup plugin for javascript-obfuscator.
Mozilla Public License 2.0
112 stars 9 forks source link

cannot obfuscate dist/public/index-nnnnn.js only. #13

Closed Pleizz closed 1 year ago

Pleizz commented 1 year ago

obfuscator({ include: "" })]

obfuscate specific file only doesn't work. include 'dist/public/index-nnn.js' only.. tried

'*/index-.js' '/index.js' 'public/index-*.js' ... etc

can i get some advices?

getkey commented 1 year ago

You have to disable globalOptions, like so:

obfuscator({
    globalOptions: false,
    include: 'index.js',
})

Closing, reopen if that doesn't solve your issue.

Pleizz commented 1 year ago

`import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; import obfuscator from "rollup-plugin-obfuscator";

export default defineConfig({ plugins: [react()], test: { globals: true, environment: "jsdom", }, build: { assetsDir: "./public", rollupOptions: { output: { plugins: [ obfuscator({ include: "index.js", exclude: "*", }), ], manualChunks(id) { if (id.includes("nodemodules")) { return "module" + id.split("node_modules")[1].split("/")[1]; } }, }, }, }, }); `

build without obfuscate works fine. but error occured from ant design with white empty screen.

image

as a result, i wanna obfuscate only my code except node_modules file.

obfuscator({ include: 'index.js', exclude: '*' })

this didn't work for me.

image this file must not be obfuscated.

can i get some advice?

thank you ^--^

p.s. under is list of files.

image

Pleizz commented 1 year ago

You have to disable globalOptions, like so:

obfuscator({
  globalOptions: false,
  include: 'index.js',
})

Closing, reopen if that doesn't solve your issue.

Oh, i've tried your edited code. but all of the file didn't obfuscated. maybe include only dist/public/index-~~~~.js

tried:

include index-.js public/index-.js */index-.js

thank you

getkey commented 1 year ago

Oh, I thought you only wanted to obfuscate index.js, that's what https://github.com/getkey/rollup-plugin-obfuscator/issues/13#issuecomment-1384302215 does.

i wanna obfuscate only my code except node_modules file

This is what the default of exclude and include does. So you just need to disable globalOptions.

obfuscator({
    globalOptions: false,
})
Pleizz commented 1 year ago

Exactly, i wanna obfuscate "src/app.tsx" file. this file became "dist/public/index-aslkfj.js" after bundling.

which file should i try?

before bundling or after bundling..

before bundling: 'src/app.tsx' after bundling: 'dist/public/index-randomStr.js'

thank you ^--^

getkey commented 1 year ago

rollup-plugin-obfuscator doesn't look at the filename after bundling, it looks at the filename before. So if you want to obfuscate only src/app.tsx, do include: 'src/app.tsx'. If you want to obfuscate all your code (but no node modules), the default needs no change.

But keep globalOptions to false. globalOptions runs a second pass after fileOptions on the entire bundle. This is not what you want here.

Pleizz commented 1 year ago

rollup-plugin-obfuscator doesn't look at the filename after bundling, it looks at the filename before. So if you want to obfuscate only src/app.tsx, do include: 'src/app.tsx'. If you want to obfuscate all your code (but no node modules), the default needs no change.

But keep globalOptions to false. globalOptions runs a second pass after fileOptions on the entire bundle. This is not what you want here.

i've tried but didn't work T.T so.. i edited static module.. this works.. thank you for helping me ^--^ happy new year and have a nice day :))

image