Skip to content

Commit fbe3068

Browse files
committed
New section - Project folders & files
- Replaced section `Folder structure` with `Project folders & files`.
1 parent 2d6555a commit fbe3068

File tree

1 file changed

+113
-24
lines changed

1 file changed

+113
-24
lines changed

README.md

Lines changed: 113 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,119 @@ To package your Electron app, run `npm run prod` to get your code compiled in
8989
uses Webpack to minify your code in `production` builds, so there shouldn't
9090
be any significant performance different with `asar` archiving disabled.
9191

92-
## Folder structure
93-
```
94-
electron-react-typescript-base-proj/
95-
| - dist/ //- Generated by Webpack automatically
96-
| - node_modules/
97-
| - out/ //- Generated by build script automatically
98-
| - public/ //- Global static assets
99-
| | - index.html
100-
| | - style.css
101-
| - src/
102-
| | - main/ //- Backend modules for the Electron app
103-
| | | - main.ts //- Entry point of 'electron-main'
104-
| | - models/
105-
| | - renderer/ //- Frontend React components for the Electron app
106-
| | | - renderer.tsx //- Entry point of 'electron-renderer'
107-
| | - utils/ //- Common utilities
108-
| - test/ //- Unit tests
109-
| - .eslintrc //- ESLint config
110-
| - .gitignore
111-
| - package-lock.json
112-
| - package.json
113-
| - tsconfig.json //- TypeScript config
114-
| - webpack.config.js //- Webpack config
115-
```
92+
## Project folders & files
93+
- `dist/` - [Webpack] output location
94+
95+
__Contents will be flushed automatically on execution of `npm run <dev|prod>`
96+
script.__
97+
98+
- `out/` - [`electron-builder`] output location
99+
100+
- `public/` - Global static assets.
101+
- `index.html` - Template for `HTML Webpack Plugin`
102+
103+
Update the value of `<title>` tag to change the default window title.
104+
105+
- `style.css` - `CSS` file location sample
106+
107+
Not much defined in this file. You can either put your `CSS` settings here
108+
or use any other tools you prefer.
109+
110+
- `src/` - Folder for all your source code
111+
- `main/` - For modules which run on the `main` process.
112+
- `main.ts` - [Electron] `main` process entry point
113+
114+
- `preload` - Preload scripts go here
115+
- `ipc-api.ts` - APIs for IPC between `main` & `renderer`
116+
117+
Consider convert this module into a collection of submodules if you have
118+
many APIs for IPC. See example as below:
119+
```ts
120+
// ipc-api/index.ts
121+
import submoduleA from './submodule-a';
122+
import submoduleB from './submodule-b';
123+
124+
export default { ...submoduleA, ...submoduleB };
125+
126+
// ipc-api/submodule-a.ts
127+
import { ipcRenderer } from 'electron';
128+
129+
function a { ipcRenderer.send('a'); }
130+
131+
export default { a };
132+
133+
// ipc-api/submodule-b.ts
134+
import { ipcRenderer } from 'electron';
135+
136+
function b { ipcRenderer.send('b'); }
137+
138+
export default { b };
139+
```
140+
141+
- `preload.ts` - [Electron] preload script entry point
142+
143+
There should be no need to modify this file unless you want to use other
144+
key(s) for your IPC APIs. By default, all APIs defined in `ipc-api`
145+
module are exposed under key `ipcApi` in `contextBridge`.
146+
147+
- `renderer/` - Where the frontend scripts stay
148+
- `App.tsx` - Root [React] component
149+
- `renderer.tsx` - [Electron] `renderer` process entry point
150+
151+
*`public/style.css` imported here. Change it if you want.*
152+
153+
- `types/` - Home for self-defined `.d.ts` files
154+
- `global.d.ts` - Extends global scope interfaces
155+
156+
This file includes ambient declaration for calling the IPC APIs defined in
157+
`preload/ipc-api` from the `renderer`. Remember __NOT__ to remove this
158+
part, otherwise TypeScript will tell you `type not exist`. However, if
159+
you've opted to use a different key other than `ipcAPI` in the preload
160+
script, __DO__ remember to update this file to match your own settings.
161+
162+
- `utils/` - Place to store the helper scripts
163+
- `node-env.ts` - Shortcut to determine `NODE` environment
164+
165+
- `tests/` - Unit testing files location
166+
167+
To avoid test files mixing up with the source code, [Jest] is configured to
168+
look for test file(s) within this folder only.
169+
170+
File name of the test files can either be `[filename].test.tsx` or
171+
`[filename].spec.ts(x)`. `js(x)` can also be used for test files, but I assume
172+
you'd use TypeScript if you're using this boilerplate.
173+
174+
- `main/main.spec.ts` - Sample test file for `src/main/main`
175+
- `tsconfig.json` - TypeScript config file for `tests` module
176+
- `.eslintignore` - [ESLint] ignore file
177+
- `.eslintrc` - [ESLint] config file
178+
179+
Configured to use Airbnb's rules with [TypeScript] supported, and rules for
180+
[Jest] applied.
181+
182+
- `.gitignore` - Git ignore file
183+
- `CHANGELOG.md` - Change log of this boilerplate
184+
- `jest.config.js` - [Jest] config file
185+
- `LICENSE` - MIT license
186+
- `package-lock.json`
187+
- `package.json`
188+
189+
Includes basic build config for `electron-builder`. It's likely that you'll
190+
have to personalise the build config when it comes to the time you're about
191+
to release your app. Please read [`electron-builder`'s document] for the
192+
build config setup guides.
193+
194+
- `README.md`
195+
- `tsconfig.json` - [TypeScript] config file
196+
197+
Module path aliases are configured here. [Jest] & [Webpack] will pick up the
198+
alias settings here to config their own. No need to manually config in Jest
199+
& Webpack again.
200+
201+
- `webpack.config.json` - [Webpack] config file
202+
203+
Includes configurations targetting `electron-main`, `electron-preload`, and
204+
`electron-renderer` respectively.
116205

117206
## Author
118207
[Wing Chau](https://github.com/iamWing) [@Devtography](https://github.com/Devtography)

0 commit comments

Comments
 (0)