getkey / rollup-plugin-obfuscator

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

TypeError: obfuscator is not a function #12

Closed doroved closed 1 year ago

doroved commented 1 year ago

Describe the bug

Hi, I have this error TypeError: obfuscator is not a function

I'm using code like this.

import { fileURLToPath, URL } from 'node:url'
import obfuscator from 'rollup-plugin-obfuscator'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  base: '',
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  build: {
    outDir: 'chrome/store/app',
     rollupOptions: {
       output: {
         plugins: [obfuscator({})],
       },
     },
  },
})

Stack trace image

Package versions:

molinla commented 1 year ago

this working in vite: 3.2.0 image

import obfuscatorModule, { RollupPluginObfuscatorOptions } from "rollup-plugin-obfuscator";

const obfuscator: (override: Partial<RollupPluginObfuscatorOptions>) => Plugin = (obfuscatorModule as any).default
doroved commented 1 year ago

this working in vite: 3.2.0 image

import obfuscatorModule, { RollupPluginObfuscatorOptions } from "rollup-plugin-obfuscator";

const obfuscator: (override: Partial<RollupPluginObfuscatorOptions>) => Plugin = (obfuscatorModule as any).default

How can I use this without TS?

molinla commented 1 year ago

this working in vite: 3.2.0 image

import obfuscatorModule, { RollupPluginObfuscatorOptions } from "rollup-plugin-obfuscator";

const obfuscator: (override: Partial<RollupPluginObfuscatorOptions>) => Plugin = (obfuscatorModule as any).default

How can I use this without TS?

just simply remove the type :)

import obfuscatorModule from "rollup-plugin-obfuscator";

const obfuscator = obfuscatorModule.default
doroved commented 1 year ago

this working in vite: 3.2.0 image

import obfuscatorModule, { RollupPluginObfuscatorOptions } from "rollup-plugin-obfuscator";

const obfuscator: (override: Partial<RollupPluginObfuscatorOptions>) => Plugin = (obfuscatorModule as any).default

How can I use this without TS?

just simply remove the type :)

import obfuscatorModule from "rollup-plugin-obfuscator";

const obfuscator = obfuscatorModule.default

Yes, that's exactly what I did.) But I got this message, without obfuscating the code

The "transform" hook used by the output plugin rollup-plugin-obfuscator is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.

image
molinla commented 1 year ago

i try to set the obfuscator-config options in both "fileOptions" and "globalOptions", and use cdn to exclude "vue" ,"vue-router" or other libs, it's working. image

this is my config: image

molinla commented 1 year ago

put it in here , everthing will just be fine 👌 cdn not working :(

image

getkey commented 1 year ago

Fixed in v1.0.1!

Make sure to read the usage again after you update, the API has changed since v1.0.0.