Skip to content

Commit

Permalink
feat: esbuild multiple main config
Browse files Browse the repository at this point in the history
Breaking Changes: remove esbuild for renderer
  • Loading branch information
Kiyozz committed May 16, 2024
1 parent 666eeb2 commit 81eff56
Show file tree
Hide file tree
Showing 60 changed files with 375 additions and 1,338 deletions.
1 change: 1 addition & 0 deletions packages/create-app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Breaking Changes

- change to pure ESM
- remove esbuild as renderer bundler

### Changes

Expand Down
2 changes: 0 additions & 2 deletions packages/create-app/src/enums/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

export enum Template {
ReactTypeScript = 'react-ts',
ReactJavaScript = 'react',
ReactViteJavaScript = 'react-vite',
ReactViteTypeScript = 'react-vite-ts',
MainOnlyTypeScript = 'main-ts',
Expand Down
2 changes: 0 additions & 2 deletions packages/create-app/src/helpers/is-template-valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Template } from '../enums/template.js'
export const TEMPLATES = [
yellow(Template.MainOnlyJavaScript),
yellow(Template.MainOnlyTypeScript),
cyan(Template.ReactJavaScript),
cyan(Template.ReactTypeScript),
cyan(Template.ReactViteJavaScript),
cyan(Template.ReactViteTypeScript),
red(Template.SvelteJavaScript),
Expand Down
23 changes: 16 additions & 7 deletions packages/create-app/templates/main-ts/esbuild.main.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { BuildOptions } from 'esbuild'
import type { BuildOptions } from 'esbuild'
import * as path from 'node:path'

const config: BuildOptions = {
const main: BuildOptions = {
platform: 'node',
entryPoints: [
path.resolve('src/main/main.ts'),
path.resolve('src/main/preload.ts'),
],
entryPoints: [path.resolve('src/main/main.ts')],
bundle: true,
format: 'esm',
target: 'node20.11.1', // electron version target
}

export default config
const preload: BuildOptions = {
platform: 'node',
entryPoints: [path.resolve('src/main/preload.ts')],
bundle: true,
format: 'esm',
target: 'node20.11.1', // electron version target
// it is important to use .mjs extension for preload script because of how electron load preload script
outExtension: {
'.js': '.mjs',
}
}

export default [main, preload]
4 changes: 3 additions & 1 deletion packages/create-app/templates/main-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"package": "electron-builder"
},
"type": "module",
"author": "built by electron-esbuild",
"description": "A simple Electron app built with electron-esbuild",
"devDependencies": {
"@types/node": "^20.11.1",
"electron": "^30.0.6",
"electron-builder": "^24.13.3",
"electron-esbuild": "^8.0.0",
"electron-esbuild": "^9.0.0",
"electron-util": "^0.18.1",
"esbuild": "^0.21.2",
"typescript": "~5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/main-ts/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function createWindow() {
minHeight: 600,
minWidth: 650,
webPreferences: {
preload: path.join(dirname, 'preload.js'),
preload: path.join(dirname, 'preload.mjs'),
},
show: false,
})
Expand Down
24 changes: 18 additions & 6 deletions packages/create-app/templates/main/esbuild.main.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import * as path from 'node:path'

/** @var {Partial<import('esbuild').BuildOptions>} */
export default {
/** @var {import('esbuild').BuildOptions} */
const main = {
platform: 'node',
entryPoints: [
path.resolve('src/main/main.js'),
path.resolve('src/main/preload.js'),
],
entryPoints: [path.resolve('src/main/main.js')],
bundle: true,
format: 'esm',
target: 'node20.11.1', // electron version target
}

/** @var {import('esbuild').BuildOptions} */
const preload = {
platform: 'node',
entryPoints: [path.resolve('src/main/preload.js')],
bundle: true,
format: 'esm',
target: 'node20.11.1', // electron version target
// it is important to use .mjs extension for preload script because of how electron load preload script
outExtension: {
'.js': '.mjs',
}
}

export default [main, preload]
4 changes: 3 additions & 1 deletion packages/create-app/templates/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"package": "electron-builder"
},
"type": "module",
"author": "built by electron-esbuild",
"description": "A simple Electron app built with electron-esbuild",
"devDependencies": {
"electron": "^30.0.6",
"electron-builder": "^24.13.3",
"electron-esbuild": "^8.0.0",
"electron-esbuild": "^9.0.0",
"electron-util": "^0.18.1",
"esbuild": "^0.21.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/main/src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function createWindow() {
minHeight: 600,
minWidth: 650,
webPreferences: {
preload: path.join(dirname, 'preload.js'),
preload: path.join(dirname, 'preload.mjs'),
},
show: false,
})
Expand Down
1 change: 0 additions & 1 deletion packages/create-app/templates/react-ts/README-template.md

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions packages/create-app/templates/react-ts/esbuild.main.config.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/create-app/templates/react-ts/esbuild.renderer.config.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/create-app/templates/react-ts/gitignore

This file was deleted.

65 changes: 0 additions & 65 deletions packages/create-app/templates/react-ts/package.json

This file was deleted.

Empty file.
67 changes: 0 additions & 67 deletions packages/create-app/templates/react-ts/src/main/main.ts

This file was deleted.

22 changes: 0 additions & 22 deletions packages/create-app/templates/react-ts/src/renderer/App.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions packages/create-app/templates/react-ts/src/renderer/index.css

This file was deleted.

17 changes: 0 additions & 17 deletions packages/create-app/templates/react-ts/src/renderer/index.html

This file was deleted.

7 changes: 0 additions & 7 deletions packages/create-app/templates/react-ts/src/renderer/index.tsx

This file was deleted.

Loading

0 comments on commit 81eff56

Please sign in to comment.