|
| 1 | +import { createRequire } from 'node:module'; |
| 2 | + |
| 3 | +import type { ForgeConfig } from '@electron-forge/shared-types'; |
| 4 | +import { MakerSquirrel } from '@electron-forge/maker-squirrel'; |
| 5 | +import { MakerZIP } from '@electron-forge/maker-zip'; |
| 6 | +import { MakerDeb } from '@electron-forge/maker-deb'; |
| 7 | +import { MakerRpm } from '@electron-forge/maker-rpm'; |
| 8 | +import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives'; |
| 9 | +import { WebpackPlugin } from '@electron-forge/plugin-webpack'; |
| 10 | +import type { Configuration, ModuleOptions } from 'webpack'; |
| 11 | +import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; |
| 12 | + |
| 13 | +const require = createRequire(import.meta.url); |
| 14 | + |
| 15 | +const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); |
| 16 | + |
| 17 | +const webpackPlugins = [ |
| 18 | + new ForkTsCheckerWebpackPlugin({ |
| 19 | + //logger: 'webpack-infrastructure' |
| 20 | + }) |
| 21 | +]; |
| 22 | + |
| 23 | +const defaultWebpackRules: () => Required<ModuleOptions>['rules'] = () => { |
| 24 | + return [ |
| 25 | + // Add support for native node modules |
| 26 | + { |
| 27 | + // We're specifying native_modules in the test because the asset relocator loader generates a |
| 28 | + // "fake" .node file which is really a cjs file. |
| 29 | + test: /native_modules[/\\].+\.node$/, |
| 30 | + use: 'node-loader' |
| 31 | + }, |
| 32 | + { |
| 33 | + test: /[/\\]node_modules[/\\].+\.(m?js|node)$/, |
| 34 | + parser: { amd: false }, |
| 35 | + use: { |
| 36 | + loader: '@vercel/webpack-asset-relocator-loader', |
| 37 | + options: { |
| 38 | + outputAssetBase: 'native_modules' |
| 39 | + } |
| 40 | + } |
| 41 | + }, |
| 42 | + { |
| 43 | + test: /\.tsx?$/, |
| 44 | + exclude: /(node_modules|\.webpack)/, |
| 45 | + use: { |
| 46 | + loader: 'ts-loader', |
| 47 | + options: { |
| 48 | + transpileOnly: true |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + ]; |
| 53 | +}; |
| 54 | + |
| 55 | +const mainConfig: Configuration = { |
| 56 | + /** |
| 57 | + * This is the main entry point for your application, it's the first file |
| 58 | + * that runs in the main process. |
| 59 | + */ |
| 60 | + entry: './src/main/index.ts', |
| 61 | + // Put your normal webpack config below here |
| 62 | + module: { |
| 63 | + rules: defaultWebpackRules(), |
| 64 | + }, |
| 65 | + plugins: webpackPlugins, |
| 66 | + resolve: { |
| 67 | + extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'] |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +const rendererConfig: Configuration = { |
| 72 | + module: { |
| 73 | + rules: [ |
| 74 | + ...defaultWebpackRules(), |
| 75 | + { |
| 76 | + test: /\.css$/, |
| 77 | + use: [{ loader: 'style-loader' }, { loader: 'css-loader' }] |
| 78 | + } |
| 79 | + ], |
| 80 | + }, |
| 81 | + plugins: webpackPlugins, |
| 82 | + resolve: { |
| 83 | + extensions: ['.js', '.ts', '.jsx', '.tsx', '.css'] |
| 84 | + } |
| 85 | +}; |
| 86 | + |
| 87 | +const config: ForgeConfig = { |
| 88 | + packagerConfig: { |
| 89 | + asar: true |
| 90 | + }, |
| 91 | + rebuildConfig: {}, |
| 92 | + makers: [ |
| 93 | + new MakerSquirrel(), |
| 94 | + new MakerZIP({}, ['darwin']), |
| 95 | + new MakerRpm({ options: { icon: './public/icons/icon' } }), |
| 96 | + new MakerDeb({ options: { icon: './public/icons/icon' } }) |
| 97 | + ], |
| 98 | + plugins: [ |
| 99 | + new AutoUnpackNativesPlugin({}), |
| 100 | + new WebpackPlugin({ |
| 101 | + mainConfig, |
| 102 | + renderer: { |
| 103 | + config: rendererConfig, |
| 104 | + entryPoints: [ |
| 105 | + { |
| 106 | + name: 'main_window', |
| 107 | + html: './src/render/index.html', |
| 108 | + js: './src/render/main.ts' |
| 109 | + } |
| 110 | + ] |
| 111 | + } |
| 112 | + }) |
| 113 | + ] |
| 114 | +}; |
| 115 | + |
| 116 | +export default config; |
0 commit comments