5

edit: I solved this by using electron-builder, it uses webpack under the hood so all problems are handled well by default. I post this question as I used electron-forge and electron-packager at first, and although I searched several resources I still couldn't wrap my head about the difference among electron-forge/electron-packager/electron-builder

original question:

I built an electron app with electron-forge using react and typescript, but I found out it contains my whole typescript source code in the distribution.

After dug around, it seems that there's no way to get rid of the source, even asar could be extracted easily. Minifying the source code may be the most "proper" way to keep others from just copy and paste my project. I figured may be I can achieve this by utilizing the afterCopy hooks provided by electron-packager, but don't know how exactly I should do it, any suggestions?

Drake Xiang
  • 368
  • 1
  • 7
  • 14
  • Why not use something like [UglifyJs](https://github.com/mishoo/UglifyJS2) before building the app and then use the ugly js files for the build? You could chain the comments in an npm script. – Mattstir Jan 23 '20 at 10:00
  • @Mattstir I don't remember exactly but I think that's what I meant to do, just didn't figure out how. I turned to use `electron-builder` to build my app at last and all these 'minifying' and 'contain ts source' problem are all handled by default. – Drake Xiang Jan 24 '20 at 17:49

2 Answers2

1

You can use bytenode for compiling all your js files into bytecode and it will be literally unreadable by humans. But it is quite hacky.

sanperrier
  • 606
  • 5
  • 12
0

You shouldn't include your typescript source code in your production package. Consider your Electron-builder configuration. Just import the bundled codes to your package.

There are some webpack plugins and so many kinds of stuff to uglify your bundled js files.

Check this as builder configuration reference.

How to deploy an Electron app as an executable or installable in Windows?

https://www.electron.build/configuration/configuration

tpikachu
  • 4,478
  • 2
  • 17
  • 42
  • Electron-builder was my solution too, I post this question when I started with electron-packager which includes ts source into bundle by default and I didn't know how to remove it – Drake Xiang Aug 06 '20 at 06:34