question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
caoxiemeihaocommented, Oct 9, 2022

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

2reactions
caoxiemeihaocommented, 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
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML: using external .js file with import statements
js which I have imported in the head of my HTML file. Everything seems to work great, until my ~/src/Main.
Read more >
API - esbuild
This setting is a convention from Webpack that esbuild respects for any imported file, not just files used with inject. #Loader. Supported by:...
Read more >
How to Optimize JavaScript Delivery to Speed Up Your Site
Use minified JS files​​ True minification also uses obfuscation, which renames variables to names that require fewer bytes of data for the browser...
Read more >
How to use an external JS file and CSS file on a Mac - Quora
Minified javaScript files are used to speed up loading of web page. Minification process remove unnecessary spaces and returns (redundant code in some...
Read more >
How to use external JS files and JavaScript code in Angular 6/7
In this tutorial you can learn how to use external js files and how to use JavaScript code in Angular 6/7.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found