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

External js files (import by main entry file) built without obfuscation or minify #86

Closed
jooy2 opened this issue Oct 6, 2022 · 5 comments

Comments

@jooy2
Copy link

jooy2 commented Oct 6, 2022

My project has the following directory structure:

src
    ㄴ main
        ㄴ utils
            test.js
        index.js
    ㄴ renderer
        main.js
        ...

If i build the package using vite-plugin-electron, the build succeeds, but when i import and use an external js file like the src/main/utils/test.js file, the file is built without minify or code obfuscation. The main/utils/test.js file in the build output path is the same as the existing file.

Is there a way to obfuscate (or minify) external js files other than the main entry file? Or is this a bug?

here is my vite.config.js:

import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron'
import vue from '@vitejs/plugin-vue'
import { resolve, join } from 'path'
import { builtinModules } from 'module'

export default defineConfig({
  base: './',
  root: resolve('./src/renderer'),
  publicDir: resolve('./src/renderer/public'),
  build: {
    outDir: resolve('./dist')
  },
  plugins: [
    vue(),
    electron({
      main: {
        entry: 'src/main/index.js',
        vite: {
          publicDir: resolve('./src/main'),
          build: {
            emptyOutDir: true,
            assetsDir: '.',
            outDir: 'dist/main',
            rollupOptions: {
              external: [
                'electron',
                ...builtinModules
              ]
            }
          }
        }
      },
      renderer: {}
    })
  ]
})

Thank you.

@caoxiemeihao
Copy link
Member

All files will be built into one file into dist/electron/main/index.js by default.

@jooy2
Copy link
Author

jooy2 commented Oct 6, 2022

Thanks for the quick reply.

I try to write efficient code by splitting multiple actions into each file.

So is there any other way to minify multiple files? I'd like to know how, if possible.
If not, are there any plans to fix it in the future?

Thanks,

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Oct 6, 2022

Minify multiple files planned next version(coming soon). But waiting for Vite's lib.entry to support multi-entry, I have noticed that the latest code already supports multi-entry, ant it should be supported in Vite@3.2.0 version. I'm also waiting for it to be released. 😄

image

@jooy2
Copy link
Author

jooy2 commented Oct 6, 2022

Thanks for the clear explanation! That is a good news. I will wait until it is officially supported, and i will check it as soon as it is supported.

You can close this issue now or after supported.

@caoxiemeihao caoxiemeihao mentioned this issue Oct 9, 2022
1 task
@caoxiemeihao
Copy link
Member

Hi here! 👋
The feature implemented in v0.10.0 #89

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