以下Webpack配置不包括{ target: electron-renderer }
,仅包含electron-main
设置。
module.exports = (env, argv) => {
return {
name: 'Electron: main process',
target: 'electron-main',
context,
entry: {
'InitializeProject_GUI': './InitializeProject_GUI.ts',
},
output: {
path: __dirname,
filename: '[name].js'
},
node: {
__dirname: false,
__filename: false
},
// ...
}
};
尽管如此,命令election InitializeProject_GUI.js
将启动我的应用程序:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My app</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
import URL from 'url';
import Path from 'path';
import {
app as electronApplication,
App as ElectronApplication,
BrowserWindow
} from 'electron';
import enableElectronDebug from 'electron-debug';
class ProjectInitializer {
private electronApplication: ElectronApplication;
private mainWindow: BrowserWindow | null = null;
private static SOURCE_FILES_DIRECTORY_RELATIVE_PATH: string = 'Source';
private static MARKUP_AND_STYLES_DIRECTORY_RELATIVE_PATH: string = 'GUI';
private static MAIN_WINDOW_MARKUP__FILE_NAME_WITH_EXTENSION: string = 'MainWindow.html';
private constructor() {
this.electronApplication = electronApplication;
enableElectronDebug();
this.electronApplication.on('ready', this.onApplicationReadyEventHandler.bind(this));
}
public static start(): void {
const projectInitializer: ProjectInitializer = new ProjectInitializer();
}
private onApplicationReadyEventHandler(): void {
this.mainWindow = new BrowserWindow({
width: 640,
height: 500,
titleBarStyle: 'hidden'
});
this.mainWindow.loadURL(URL.format({
pathname: Path.join(
__dirname,
ProjectInitializer.SOURCE_FILES_DIRECTORY_RELATIVE_PATH,
ProjectInitializer.MARKUP_AND_STYLES_DIRECTORY_RELATIVE_PATH,
ProjectInitializer.MAIN_WINDOW_MARKUP__FILE_NAME_WITH_EXTENSION
),
protocol: 'file:',
slashes: true
}));
this.mainWindow.setMenu(null);
}
}
(function executeApplication(): void {
ProjectInitializer.start();
})();
为什么我的应用程序在没有渲染器({ target: electron-renderer }
)脚本文件的情况下可以工作?