-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent vite's minifier from undoing obfuscation #16
Comments
When you remove the plugin from your config, what do you get? |
I'm pretty sure this is the result of rollup-plugin-obfuscator running before minification. Could you disable minification to test that theory? It's not possible to make rollup-plugin-obfuscator run after minification, even with |
Yes, with minify:false it will obfuscate properly Why then does the vite-plugin-obfuscator plugin work correctly and the obfuscated code is minified? But it obfuscates all code, including library code, which is unnecessary. |
This is how vite-plugin-obfuscator works. |
I tried, but I haven't been able to make vite-plugin-obfuscator work. Please make a repo with a minimal reproduction case and send me the link so I can look how it works. |
Use this config and everything should work fine. vite.config.js import { fileURLToPath, URL } from 'node:url'
import { viteObfuscateFile } from 'vite-plugin-obfuscator'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue(), viteObfuscateFile()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
}) If it does not work now, I will prepare a repository. |
Thanks, I was able to reproduce and have a deeper look at what that plugin is doing. It is modifying the bundle during the HTML transform phase, which apparently happens after the minification. Unfortunately this technique does not allow excluding libraries from the bundle. Now the question is, should rollup-plugin-obfuscator adopt this technique when
So for all these reasons, I think it would make for a bad addition. If you want to do it anyway, here is the alternative way to do it I was talking about in 2. (it will exclude library code): // vite.config.js
import { defineConfig } from 'vite';
import obfuscator from 'rollup-plugin-obfuscator';
import terser from '@rollup/plugin-terser';
export default defineConfig({
build: {
minify: false,
},
plugins: [
terser(),
obfuscator(),
],
}); |
Thank you. It all worked out.
I have one more question, I want the obfuscation code to look like this
But your plugin obfuscates like this
I would like to have the first example of how to do this?
I am using the default options.
In the first example plugin: vite-plugin-obfuscator
Originally posted by @doroved in #15 (comment)
The text was updated successfully, but these errors were encountered: