Switch from electron-webpack to electron-forge

This commit is contained in:
Matthias Schiffer 2020-02-22 17:35:19 +01:00
parent d35a68caf3
commit 9eed5c04ff
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
10 changed files with 1777 additions and 2615 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
/dist
/node_modules /node_modules
/.webpack

View file

@ -1,5 +0,0 @@
{
"renderer": {
"webpackConfig": "webpack.renderer.js"
}
}

View file

@ -1,20 +1,48 @@
{ {
"private": true, "private": true,
"version": "0.0.0",
"main": ".webpack/main",
"scripts": { "scripts": {
"start": "electron-webpack dev", "start": "electron-forge start",
"lint": "eslint 'src/**/*.ts'" "lint": "eslint 'src/**/*.ts'"
}, },
"config": {
"forge": {
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.js",
"renderer": {
"config": "./webpack.renderer.js",
"entryPoints": [
{
"html": "./src/renderer/index.html",
"js": "./src/renderer/index.ts",
"name": "main_window"
}
]
}
}
]
]
}
},
"devDependencies": { "devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.49",
"@electron-forge/plugin-webpack": "^6.0.0-beta.49",
"@typescript-eslint/eslint-plugin": "^2.20.0", "@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0", "@typescript-eslint/parser": "^2.20.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.4.2",
"electron": "^8.0.1", "electron": "^8.0.1",
"electron-webpack": "^2.7.4",
"electron-webpack-ts": "^3.2.0",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0", "eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2", "eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"raw-loader": "^4.0.0", "raw-loader": "^4.0.0",
"style-loader": "^1.1.3",
"ts-loader": "^6.2.1",
"typescript": "^3.8.2", "typescript": "^3.8.2",
"webpack": "^4.41.6" "webpack": "^4.41.6"
}, },

View file

@ -1,60 +1,40 @@
import { app, BrowserWindow } from 'electron'; import { app, BrowserWindow } from 'electron';
import * as path from 'path'; declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
import { format as formatUrl } from 'url';
const isDevelopment = process.env.NODE_ENV !== 'production'; const isDevelopment = process.env.NODE_ENV !== 'production';
// global reference to mainWindow (necessary to prevent window from being garbage collected) app.allowRendererProcessReuse = true;
let mainWindow: BrowserWindow | null = null;
function getIndexURL(): string { function createWindow(): void {
if (isDevelopment) {
return `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`;
}
return formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true,
});
}
function createMainWindow(): BrowserWindow {
const window = new BrowserWindow({ webPreferences: { nodeIntegration: true } }); const window = new BrowserWindow({ webPreferences: { nodeIntegration: true } });
window.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
if (isDevelopment) { if (isDevelopment) {
window.webContents.openDevTools(); window.webContents.openDevTools();
} }
window.loadURL(getIndexURL());
window.on('closed', () => {
mainWindow = null;
});
window.webContents.on('devtools-opened', () => { window.webContents.on('devtools-opened', () => {
window.webContents.focus(); window.webContents.focus();
}); });
return window;
} }
// quit application when all windows are closed // quit application when all windows are closed
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits // On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit(); app.quit();
} }
}); });
app.on('activate', () => { app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed // On macOS it's common to re-create a window in the app when the
if (!mainWindow) { // dock icon is clicked and there are no other windows open.
mainWindow = createMainWindow(); if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
} }
}); });
// create main BrowserWindow when electron is ready // create main BrowserWindow when electron is ready
app.on('ready', () => { app.on('ready', createWindow);
mainWindow = createMainWindow();
});

11
src/renderer/index.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>RPGedit</title>
</head>
<body>
<div id="app"></div>
</body>
</html>

View file

@ -5,8 +5,7 @@
"strict": true, "strict": true,
"jsx": "react", "jsx": "react",
"outDir": "dist", "outDir": "dist",
"sourceMap": true, "sourceMap": true
"declaration": true
}, },
"include": [ "include": [
"src/**/*" "src/**/*"

15
webpack.main.js Normal file
View file

@ -0,0 +1,15 @@
module.exports = {
entry: './src/main/index.ts',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
};

View file

@ -1,7 +1,26 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const CopyPlugin = require('copy-webpack-plugin');
module.exports = { module.exports = {
module: { module: {
rules: [ rules: [
{ test: /\.(vs|fs)$/, use: ['raw-loader'] }, {
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
{
test: /\.(vs|fs)$/,
use: 'raw-loader',
},
], ],
}, },
} plugins: [new CopyPlugin([{ from: 'static' }])],
resolve: {
extensions: ['.ts', '.js', '.tsx', '.jsx'],
},
};

10
webpack.rules.js Normal file
View file

@ -0,0 +1,10 @@
module.exports = [
// Add support for native node modules
{
test: /\.tsx?$/,
exclude: /(node_modules|\.webpack)/,
use: {
loader: 'ts-loader'
}
},
];

4245
yarn.lock

File diff suppressed because it is too large Load diff