Skip to content

Commit d533e49

Browse files
committed
ref/ electron builder two packages build
1 parent 154d3fc commit d533e49

11 files changed

+167
-204
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ src/**/*.js
1212
*.js.map
1313

1414
# dependencies
15-
/node_modules
15+
node_modules
1616

1717
# IDEs and editors
18-
/.idea
18+
.idea
1919
.project
2020
.classpath
2121
.c9/

README.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ npm install
4848

4949
There is an issue with `yarn` and `node_modules` when the application is built by the packager. Please use `npm` as dependencies manager.
5050

51-
5251
If you want to generate Angular components with Angular-cli , you **MUST** install `@angular/cli` in npm global context.
5352
Please follow [Angular-cli documentation](https://github.com/angular/angular-cli) if you had installed a previous version of `angular-cli`.
5453

@@ -62,17 +61,26 @@ npm install -g @angular/cli
6261

6362
Voila! You can use your Angular + Electron app in a local development environment with hot reload!
6463

65-
The application code is managed by `main.ts`. In this sample, the app runs with a simple Angular App (http://localhost:4200) and an Electron window.
66-
The Angular component contains an example of Electron and NodeJS native lib import.
67-
You can disable "Developer Tools" by commenting `win.webContents.openDevTools();` in `main.ts`.
64+
The application code is managed by `app/main.ts`. In this sample, the app runs with a simple Angular App (http://localhost:4200), and an Electron window. \
65+
The Angular component contains an example of Electron and NodeJS native lib import. \
66+
You can disable "Developer Tools" by commenting `win.webContents.openDevTools();` in `app/main.ts`.
67+
68+
## Project structure
69+
70+
|Folder|Description|
71+
| ---- | ---- |
72+
| app | Electron main process folder (NodeJS) |
73+
| src | Electron renderer process folder (Web / Angular) |
6874

6975
## Use Electron / NodeJS libraries
7076

71-
This sample project runs in both modes (web and electron). To make this work, **you have to import your dependencies the right way**. Please check `providers/electron.service.ts` to watch how conditional import of libraries has to be done when using electron / NodeJS / 3rd party libraries in renderer context (i.e. Angular).
77+
3rd party libraries used in electron's main process (like an ORM) have to be added in `dependencies` of `app/package.json`.
78+
This sample project runs in both modes (web and electron). To make this work, **you have to import your dependencies the right way**. \
7279

7380
## Use "web" 3rd party libraries (like angular, material, bootstrap, ...)
7481

75-
3rd party librairies used in electron's renderer process (like angular) have to be added in `devDependencies` of `package.json`. They are already added in your final package during webpack's compilation phase. Otherwise it will significantly increase the size of your final package... not so cool :(
82+
3rd party libraries used in electron's renderer process (like angular) have to be added in `dependencies` of `package.json`. \
83+
Please check `providers/electron.service.ts` to watch how conditional import of libraries has to be done when using NodeJS / 3rd party libraries in renderer context (i.e. Angular).
7684

7785
## Browser mode
7886

@@ -88,11 +96,13 @@ Maybe you only want to execute the application in the browser with hot reload? J
8896
|`npm run electron:local`| Builds your application and start electron
8997
|`npm run electron:build`| Builds your application and creates an app consumable based on your operating system |
9098

91-
**Your application is optimised. Only /dist folder and node dependencies are included in the executable.**
99+
**Your application is optimised. Only /dist folder and NodeJS dependencies are included in the final bundle.**
92100

93101
## You want to use a specific lib (like rxjs) in electron main thread ?
94102

95-
YES! You can do it! Just by importing your library in npm dependencies section (not **devDependencies**) with `npm install --save`. It will be loaded by electron during build phase and added to your final package. Then use your library by importing it in `main.ts` file. Quite simple, isn't it?
103+
YES! You can do it! Just by importing your library in npm dependencies section of `app/package.json` with `npm install --save XXXXX`. \
104+
It will be loaded by electron during build phase and added to your final bundle. \
105+
Then use your library by importing it in `app/main.ts` file. Quite simple, isn't it?
96106

97107
## E2E Testing
98108

angular.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"configurations": {
3131
"dev": {
3232
"optimization": false,
33-
"outputHashing": "all",
33+
"outputHashing": "none",
3434
"sourceMap": true,
3535
"namedChunks": false,
3636
"aot": false,
@@ -46,7 +46,7 @@
4646
},
4747
"web": {
4848
"optimization": false,
49-
"outputHashing": "all",
49+
"outputHashing": "none",
5050
"sourceMap": true,
5151
"namedChunks": false,
5252
"aot": false,
@@ -126,7 +126,7 @@
126126
"eslintConfig": ".eslintrc.json",
127127
"lintFilePatterns": [
128128
"src/**/*.ts",
129-
"main.ts"
129+
"app/**.ts"
130130
]
131131
}
132132
}

main.ts renamed to app/main.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { app, BrowserWindow, screen } from 'electron';
22
import * as path from 'path';
33
import * as url from 'url';
44

5+
const pad = require('pad');
6+
7+
console.log(pad('pad', 5));
8+
59
// Initialize remote module
610
require('@electron/remote/main').initialize();
711

@@ -33,13 +37,13 @@ function createWindow(): BrowserWindow {
3337
win.webContents.openDevTools();
3438

3539
require('electron-reload')(__dirname, {
36-
electron: require(`${__dirname}/node_modules/electron`)
40+
electron: require(`${__dirname}/../node_modules/electron`)
3741
});
3842
win.loadURL('http://localhost:4200');
3943

4044
} else {
4145
win.loadURL(url.format({
42-
pathname: path.join(__dirname, 'dist/index.html'),
46+
pathname: path.join(__dirname, '../dist/index.html'),
4347
protocol: 'file:',
4448
slashes: true
4549
}));

app/package-lock.json

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "angular-electron",
3+
"version": "10.0.0",
4+
"main": "main.js",
5+
"private": true,
6+
"dependencies": {
7+
"@electron/remote": "1.0.4",
8+
"pad": "3.2.0"
9+
}
10+
}

electron-builder.json

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
{
2-
"productName": "angular-electron",
32
"directories": {
43
"output": "release/"
54
},
65
"files": [
76
"**/*",
87
"!**/*.ts",
9-
"!.github",
10-
"!.vscode",
11-
"!.code-workspace",
12-
"!.npmrc",
13-
"!*.md",
8+
"!*.map",
149
"!package.json",
15-
"!package-lock.json",
16-
"!src/",
17-
"!e2e/",
18-
"!hooks/",
19-
"!_config.yml",
20-
"!angular.json",
21-
"!tsconfig*.json",
22-
"!tslint.json",
23-
"!.eslintrc.json",
24-
"!karma.conf.js",
25-
"!angular.webpack.js",
26-
"!*.map"
10+
"!package-lock.json"
11+
],
12+
"extraResources": [
13+
{
14+
"from": "dist",
15+
"to": "dist",
16+
"filter": [
17+
"**/*"
18+
]
19+
}
2720
],
2821
"win": {
2922
"icon": "dist/assets/icons",
30-
"target": ["portable"]
23+
"target": [
24+
"portable"
25+
]
3126
},
3227
"portable": {
3328
"splashImage": "dist/assets/icons/electron.bmp"
3429
},
3530
"mac": {
3631
"icon": "dist/assets/icons",
37-
"target": ["dmg"]
32+
"target": [
33+
"dmg"
34+
]
3835
},
3936
"linux": {
4037
"icon": "dist/assets/icons",
41-
"target": ["AppImage"]
38+
"target": [
39+
"AppImage"
40+
]
4241
}
4342
}

0 commit comments

Comments
 (0)