|
| 1 | +--- |
| 2 | +description: Set up your Forge configuration to use TypeScript |
| 3 | +--- |
| 4 | + |
| 5 | +# TypeScript Configuration |
| 6 | + |
| 7 | +By default, Electron Forge's [configuration](broken-reference) only supports JavaScript and JSON files as inputs. |
| 8 | + |
| 9 | +Forge also supports configuration files in other languages that transpile down to JavaScript as long as a transpiler is installed locally in your project's `devDependencies`. These configuration files follow the same format as `forge.config.js`. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +For TypeScript, we recommend installing [`ts-node`](https://github.com/TypeStrong/ts-node). Upon installation, it will automatically be registered as a module loader for `.ts` files. |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install --save-dev ts-node |
| 17 | +``` |
| 18 | + |
| 19 | +## Configuration file |
| 20 | + |
| 21 | +Once you have `ts-node` installed, Forge will be able to load a `forge.config.ts` file from your project's root directory. |
| 22 | + |
| 23 | +This config format is functionally identical to `forge.config.js`. |
| 24 | + |
| 25 | +{% code title="forge.config.ts" %} |
| 26 | +```typescript |
| 27 | +import type { ForgeConfig } from '@electron-forge/shared-types'; |
| 28 | + |
| 29 | +const config: ForgeConfig = { |
| 30 | + packagerConfig: { |
| 31 | + asar: true, |
| 32 | + osxSign: {} |
| 33 | + } |
| 34 | + makers: [ |
| 35 | + { |
| 36 | + name: '@electron-forge/maker-squirrel', |
| 37 | + platforms: ['win32'], |
| 38 | + config: { |
| 39 | + authors: "Electron contributors" |
| 40 | + } |
| 41 | + }, |
| 42 | + { |
| 43 | + name: '@electron-forge/maker-zip', |
| 44 | + platforms: ['darwin'], |
| 45 | + config: {} |
| 46 | + }, |
| 47 | + { |
| 48 | + name: '@electron-forge/maker-deb', |
| 49 | + platforms: ['linux'], |
| 50 | + config: {} |
| 51 | + }, |
| 52 | + ] |
| 53 | +}; |
| 54 | + |
| 55 | +export default config; |
| 56 | +``` |
| 57 | +{% endcode %} |
| 58 | + |
| 59 | +## Using module constructor syntax |
| 60 | + |
| 61 | +When using a TypeScript configuration file, you may want to have stronger type validation around the individual options for each Maker, Publisher, or Plugin. |
| 62 | + |
| 63 | +To achieve this, you can import each module's constructor, which accepts its config object as the first parameter and the list of target platforms as the second parameter. |
| 64 | + |
| 65 | +For example, the below configuration is equivalent to the `makers` array from the example above: |
| 66 | + |
| 67 | +{% code title="forge.config.ts" %} |
| 68 | +```typescript |
| 69 | +import type { ForgeConfig } from '@electron-forge/shared-types'; |
| 70 | +import { MakerDeb } from '@electron-forge/maker-deb'; |
| 71 | +import { MakerSquirrel } from '@electron-forge/maker-squirrel'; |
| 72 | +import { MakerZIP } from '@electron-forge/maker-zip'; |
| 73 | + |
| 74 | +const config: ForgeConfig = { |
| 75 | + makers: [ |
| 76 | + new MakerSquirrel({ |
| 77 | + authors: 'Electron contributors' |
| 78 | + }, ['win32']), |
| 79 | + new MakerZIP({}, ['darwin']), |
| 80 | + new MakerDeb({}, ['linux']), |
| 81 | + new MakerRpm({}, ['linux']), |
| 82 | + ] |
| 83 | +}; |
| 84 | + |
| 85 | +export default config; |
| 86 | +``` |
| 87 | +{% endcode %} |
0 commit comments