Skip to content
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

String protection not working when build.minify is set to true #417

Closed
4 tasks done
therealartti opened this issue Feb 22, 2024 · 2 comments
Closed
4 tasks done

String protection not working when build.minify is set to true #417

therealartti opened this issue Feb 22, 2024 · 2 comments

Comments

@therealartti
Copy link

Describe the bug

The protectedStrings option fails to find the wanted strings when build.minify is true. Removing minify: true fixes it.

Here's my electron.vite.config.js:

export default defineConfig({
  main: {
    plugins: [
      externalizeDepsPlugin(),
      bytecodePlugin({ protectedStrings: ['ABCDE', 'FGHIJ'] }),
    ],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'src/main/index.js'),
          index2: resolve(__dirname, 'src/main/index2.js'),
          index3: resolve(__dirname, 'src/main/index3.js')
        }
      },
      minify: true //works without this
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()],
    build: {
      minify: true
    }
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [react()],
    build: {
      minify: true
    }
  }
})

Enforcing the plugin ordering does not seem to help either:

plugins: [
      {
        ...bytecodePlugin({
          protectedStrings: ['ABCDE', 'FGHIJ']
        }),
        enforce: 'pre'
      },
      externalizeDepsPlugin()
    ],

Electron-Vite Version

2.0.0

Electron Version

28.2.4

Vite Version

5.1.4

Validations

alex8088 added a commit that referenced this issue Mar 3, 2024
@alex8088
Copy link
Owner

alex8088 commented Mar 3, 2024

@therealartti Thank you for your feedback. When minification is enabled, string protection has no effect. This is because string protection is based on character codes. However, modern minification tools, whether esbuild or terser, will restore the converted character codes, causing the protection to fail. electron-vite will throw a warning. In fact, minification has little effect on reducing bytecode size, so it is recommended not to enable minification when protecting strings.

@alex8088
Copy link
Owner

alex8088 commented Mar 3, 2024

new ver 2.1.0 is out 🎉.

@alex8088 alex8088 closed this as completed Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants