getkey / rollup-plugin-obfuscator

The most powerful rollup plugin for javascript-obfuscator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not working with vite and import.meta.glob

simonbuehler opened this issue · comments

Describe the bug
hi,
thanks for the pulgin!

when i use the plugin in vite and register the components with Glob imports i get
(intermediate value)[z(...)] is not a function in the source it shows

... const c0=import.meta[z(226,188,253,225)]("./componen"+B(-113,-71,-76,-53),j); ...
  • [?] to the best of my knowledge, this is a bug in rollup-plugin-obfuscator and not in javascript-obfuscator

To Reproduce

  1. import components using vite glob.meta
  2. use in vite.conf like
 build: {
    rollupOptions: {
      plugins: [
        obfuscator({
          include :['**/*.js', '**/*.ts', '**/*.vue'],
          exclude : ['node_modules/**'],
          fileOptions: {
  1. find error

Package versions:

  • rollup-plugin-obfuscator: v0.2.2
  • javascript-obfuscator: v2.19.1

Try add "enforce: 'post'" in your Plugins like this:

plugins: [
  vue(),
  {
    ...obfuscator({}),
    enforce: 'post'
  }
]

https://vitejs.dev/guide/using-plugins.html#finding-plugins

unfortunately this doesn't work and post only applies to globalOptions and not fileoptions. globalOptions doesn't allow to exclude chunks and my aim is to just obfuscate app.js and leave the vendor chunk as is

my config is

build: {
    rollupOptions: {
      plugins: [
        obfuscator({
          include :['**/*.js', '**/*.ts', '**/*.vue'],
          exclude : ['node_modules/**'],
          fileOptions: {           
            log: true,            
          },
          globalOptions: false,
        })
      ]
    },
  },
plugins: [
    splitVendorChunkPlugin(),
    vue(),
    {
      ...obfuscator({}),
      enforce: 'post'
    },
    laravel({
      input: [
        'resources/sass/app.scss',
        'resources/js/app.js',
        'resources/js/dashboard.js'], // add scss file
      refresh: true,
    }),

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({})],
       },
     },
  },
})

Can someone tell me how to solve this problem?
I only want to obfuscate the JS file of the application, not the dependencies.

@doroved please open another issue, your problem has nothing to do with this issue.

@doroved please open another issue, your problem has nothing to do with this issue.

I created a new issue, but unfortunately there is no reaction

Thanks. Indeed. That's because I haven't had time to look at either of them.

I understand you. I hope you will have time to check the issue soon, because I have not found any working alternatives to your solution

So, the problem here is that javascript-obfuscator is treating import.meta.glob() as any other function, and obfuscating it. It's unfortunate that you can't use enforce: 'post' to run the obfuscation after Vite does its replacement. But there is another trick that I have used (not with Vite though):

/* javascript-obfuscator:disable */
const modules = import.meta.glob('./dir/*.js')
/* javascript-obfuscator:enable */

If that doesn't work, reopen the issue!