Skip to content

Commit 57891dc

Browse files
author
Maxime GRIS
committed
feat/ Add electron-packager scripts
1 parent 9a983c1 commit 57891dc

File tree

5 files changed

+29
-5394
lines changed

5 files changed

+29
-5394
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/dist
55
/tmp
66
/out-tsc
7+
/app-builds
78

89
# dependencies
910
/node_modules

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ npm install
2828
## To build for development
2929

3030
**in a terminal window** -> npm start
31-
**in another terminal window** -> npm run electron
31+
**in another terminal window** -> npm run electron:serve
3232

3333
The code for this is managed at `main.js`. In this sample, the app runs with a simple Electron window.
3434
By default, Developer tools is opened. You can unactivate it by uncomment `win.webContents.openDevTools();` in `main.js`.
3535

3636
## To build for production
3737

38-
npm run build
39-
npm run electron dist
38+
- npm run electron:dist
39+
40+
You can find your builted files in the /dist directory.
41+
42+
## Included Commands
43+
44+
- `npm run electron:linux` - builds your application and creates an app consumable on linux systems.
45+
- `npm run electron:windows` - On a Windows OS, builds your application and creates an app consumable in windows 32/64 bit systems.
46+
- `npm run electron:mac` - On a MAC OS, builds your application and generates a `.app` file of your application that can be run on mac .
47+
48+
**Your executable is optimised. There are only the files of /dist directory in the executable generated.**

main.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ function createWindow() {
2020
height: size.height
2121
});
2222

23-
let url = 'http://localhost:4200';
24-
let Args = process.argv.slice(2);
23+
let url = 'file://' + __dirname + '/index.html';
24+
let Args = process.argv.slice(1);
25+
2526
Args.forEach(function (val) {
26-
if (val === "dist") {
27-
url = 'file://' + __dirname + '/dist/index.html'
27+
if (val === "--serve") {
28+
url = 'http://localhost:4200'
2829
}
2930
});
3031

package.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"name": "Maxime GRIS",
88
"email": "[email protected]"
99
},
10-
"keywords" : [
10+
"keywords": [
1111
"angular",
1212
"electron",
1313
"typescript",
@@ -18,12 +18,15 @@
1818
"scripts": {
1919
"ng": "ng",
2020
"start": "ng serve",
21-
"build": "ng build",
21+
"build": "ng build && copyfiles main.js dist",
2222
"test": "ng test",
2323
"lint": "ng lint",
2424
"e2e": "ng e2e",
25-
"electron": "electron .",
26-
"electron dist": "electron main.js"
25+
"electron:serve": "electron . --serve",
26+
"electron:dist": "npm run build && electron dist/main.js",
27+
"electron:linux": "npm run build && copyfiles package.json dist && electron-packager dist --overwrite --platform=linux --arch=x64 --asar=true --out=app-builds",
28+
"electron:windows": "npm run build && copyfiles package.json dist && electron-packager dist --overwrite --platform=win32 --arch=ia32 --asar=false --out=app-builds",
29+
"electron:mac": "npm run build && copyfiles package.json dist && electron-packager . --overwrite --platform=darwin --arch=x64 --asar=true --out=app-builds"
2730
},
2831
"dependencies": {
2932
"@angular/common": "~4.0.0",
@@ -44,15 +47,18 @@
4447
"@types/jasmine": "2.5.38",
4548
"@types/node": "~6.0.60",
4649
"codelyzer": "~2.0.0",
50+
"copyfiles": "^1.2.0",
51+
"electron": "1.6.2",
52+
"electron-packager": "~8.6.0",
4753
"electron-prebuilt": "~1.4.13",
4854
"jasmine-core": "~2.5.2",
4955
"jasmine-spec-reporter": "~3.2.0",
5056
"karma": "~1.4.1",
5157
"karma-chrome-launcher": "~2.0.0",
5258
"karma-cli": "~1.0.1",
59+
"karma-coverage-istanbul-reporter": "~0.2.0",
5360
"karma-jasmine": "~1.1.0",
5461
"karma-jasmine-html-reporter": "~0.2.2",
55-
"karma-coverage-istanbul-reporter": "~0.2.0",
5662
"protractor": "~5.1.0",
5763
"ts-node": "~2.0.0",
5864
"tslint": "~4.5.0",

0 commit comments

Comments
 (0)