Closed raphaelmenges closed 1 year ago
I can take a look into this later this week but at a guess it's running before vite is doing it's import.meta.env replacements, which is wrong
I have reproduced the issue using a popular vite+electron template in minimal fashion: https://github.com/raphaelmenges/rollup-obfuscator-bug
With rollup-obfuscator
in version 3.0.2 it works, with rollup-obfuscator
in version 4.0.0 the error is thrown upon npm run watch
.
I could fix it when importing it in Vite as following:
plugins: [
{
...obfuscator({
sourceMap: process.env.MODE === 'development',
exclude: ['./node_modules/**/*'],
target: 'node',
}),
enforce: 'post',
},
...
],
See the Vite documentation for more information about the enforce
setting. I am not sure whether such option can be set in an rollup-plugin
, or whether one would need a vite-plugin
.
@raphaelmenges that's a great find! Do you want to send over a PR? I don't imagine it'll cause any issues with rollup. If you do a pr you can check this by doing pnpm dev
in the repo and check for errors, as that runs the rollup dev environment.
It might also be ideal if we add apply: 'build'
, as it's pointless running in dev - I don't believe either would be considered a breaking change but worth documenting in the README nonetheless
Hello 👋
I am using
rollup-obfuscator
in combination with Vite and Electron. When upgrading from version3.0.2
to4.0.0
I was prompted with the following error:The corresponding line in
index.cjs
starts like following:I assume it has something to do with how
import.meta.env.DEV
of Vite is obfuscated. According to the docs of Vite,import.meta.env
should not be accessed with array brackets. I guess some default inrollup-obfuscator
or its dependencies was changed, such that it transformsimport.meta.env.DEV
differently than before?