electron-vite-vue icon indicating copy to clipboard operation
electron-vite-vue copied to clipboard

[Help] how to include additional files in dist?

Open jinusean opened this issue 2 years ago β€’ 9 comments

I have a script that is forked in the main process, how can I include this in the dist build?

jinusean avatar Sep 12 '22 10:09 jinusean

【vite-plugin-static-copy - npm】https://www.npmjs.com/package/vite-plugin-static-copy

caoxiemeihao avatar Sep 12 '22 10:09 caoxiemeihao

Sorry it is a typescript file not a static file.

jinusean avatar Sep 12 '22 10:09 jinusean

You may need additional build typescript files. This is not the default feature.

caoxiemeihao avatar Sep 12 '22 11:09 caoxiemeihao

I'm also looking into doing something similar, but with a python (during dev) and exe for (during build, via pyinstaller). I have attempted to use the linked (https://www.npmjs.com/package/vite-plugin-static-copy) but couldn't get it to work on Windows. File detected but doesn't seems to be copied over from root/py to /dist/py

hafiidz avatar Sep 17 '22 01:09 hafiidz

How can we use files, extraresources or extraFiles ya? I'm really new to electron, sorry for newbie questions

hafiidz avatar Sep 17 '22 01:09 hafiidz

image

Sharing my setup here, which unfortunately is not working. I am working on Windows.

@jinusean , sorry for cluttering your issues/help wanted, wanted to avoid duplication of issues raised. Do let me know if I need to move this elsewhere.

hafiidz avatar Sep 17 '22 02:09 hafiidz

I found out what I did wrong. For those who is here looking for something similar functionality:

  1. Just copy whatever folder that you wanted in the public folder, it would be copied over automatically during vite build
  2. Similarly, the https://www.npmjs.com/package/vite-plugin-static-copy also works, just make sure you are running vite build first.
  3. During npm run dev, you just need to check whether build or public via process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST, "../public");, and handle it accordingly.

Thanks @caoxiemeihao for the helps!

hafiidz avatar Sep 17 '22 09:09 hafiidz

@Hafiidz thank you!

jinusean avatar Sep 22 '22 16:09 jinusean

Now, a new plugin is available πŸ‘‰ vite-electron-plugin

  β”œβ”€β”¬ dist-electron // Automatically generated from the electron directory
  β”‚ └── main.js
  β”‚
  β”œβ”€β”€ static        // static files here
  β”‚
  β”œβ”€β”¬ electron      // The Electron source codes directory 
  β”‚ └── main.ts
  β”‚
  β”œβ”€β”¬ src
  β”‚ β”œβ”€β”€ main.ts
  β”‚ β”œβ”€β”€ style.css
  β”‚ └── vite-env.d.ts
  β”‚
  β”œβ”€β”€ index.html
  β”œβ”€β”€ package.json
  β”œβ”€β”€ tsconfig.json
  └── vite.config.ts

caoxiemeihao avatar Sep 30 '22 07:09 caoxiemeihao