From ff88c7047ef180efef674f64211138584d6ed655 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Fri, 15 Apr 2022 15:31:47 +0800 Subject: [PATCH] Add electron min thread entry --- config/webpack.common.js | 6 +++++- config/webpack.electron.js | 43 +++++++++++++++++++++++++++++++++++++ package-lock.json | 18 +++++++++++++++- package.json | 5 ++++- source/Electron/Electron.ts | 16 ++++++++++++++ tsconfig.json | 5 ++++- 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 config/webpack.electron.js create mode 100644 source/Electron/Electron.ts diff --git a/config/webpack.common.js b/config/webpack.common.js index dbf6665..8e9bcd0 100644 --- a/config/webpack.common.js +++ b/config/webpack.common.js @@ -80,7 +80,11 @@ const Entry = () => ({ ServiceRunner: { import: source("./Service/Runner.ts"), dependOn: ["Service"] - } + }, + + Electron: { + import: source("./Electron/Electron.ts") + }, }); /** diff --git a/config/webpack.electron.js b/config/webpack.electron.js new file mode 100644 index 0000000..0a79da0 --- /dev/null +++ b/config/webpack.electron.js @@ -0,0 +1,43 @@ +const { Entry, Output, resolve, TypeScriptRules } = require("./webpack.common"); +const nodeExternals = require("webpack-node-externals"); + +const AllEntry = Entry(); + +module.exports = (env) => { + + const config = { + + entry: { + Electron: AllEntry.Electron, + }, + + output: Output("[name].js"), + devtool: 'source-map', + mode: "development", + resolve: resolve(), + + optimization: { + splitChunks: { + chunks: 'all', + minSize: 1000 + } + }, + + externals: [nodeExternals()], + + module: { + rules: [ + TypeScriptRules() + ] + }, + + node: { + __filename: false, + __dirname: false + }, + + target: 'node' + }; + + return config; +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 038c4dc..8705181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,8 @@ "typescript": "^4.5.4", "webpack": "^5.65.0", "webpack-cli": "^4.9.1", - "webpack-dev-server": "^4.7.2" + "webpack-dev-server": "^4.7.2", + "webpack-node-externals": "^3.0.0" } }, "node_modules/@atao60/fse-cli": { @@ -7904,6 +7905,15 @@ "node": ">=10.0.0" } }, + "node_modules/webpack-node-externals": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz", + "integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/webpack-sources": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", @@ -14352,6 +14362,12 @@ "wildcard": "^2.0.0" } }, + "webpack-node-externals": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz", + "integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==", + "dev": true + }, "webpack-sources": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", diff --git a/package.json b/package.json index a037858..e3178c0 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "build-run-desktop-web": "npm run build-desktop-web & npm run copy-fluent-icon & npm run build-service & npm run run-service", "release-run-desktop-web": "npm run release-desktop-web & npm run copy-fluent-icon & npm run release-service & npm run run-service", "skip-electron-ci": "set ELECTRON_SKIP_BINARY_DOWNLOAD=1& npm ci", + "build-electron": "webpack --mode development --config ./config/webpack.electron.js", + "release-electron": "webpack --mode production --no-devtool --config ./config/webpack.electron.js", "electron-cache": "set ELECTRON_SKIP_BINARY_DOWNLOAD=& set ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/& set ELECTRON_CUSTOM_DIR={{ version }}& node ./node_modules/electron/install.js", "electron-test": "electron" }, @@ -51,7 +53,8 @@ "typescript": "^4.5.4", "webpack": "^5.65.0", "webpack-cli": "^4.9.1", - "webpack-dev-server": "^4.7.2" + "webpack-dev-server": "^4.7.2", + "webpack-node-externals": "^3.0.0" }, "dependencies": { "@fluentui/react": "^8.56.0", diff --git a/source/Electron/Electron.ts b/source/Electron/Electron.ts new file mode 100644 index 0000000..cf12dc6 --- /dev/null +++ b/source/Electron/Electron.ts @@ -0,0 +1,16 @@ +import { app, BrowserWindow } from "electron"; + +async function main() { + + await app.whenReady(); + + const win = new BrowserWindow({ + width: 800, + height: 600 + }); + + win.loadURL("https://www.baidu.com"); + +} + +main(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 01bc055..ce1f29d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -43,7 +43,10 @@ ], "@Service/*": [ "./source/Service/*" - ] + ], + "@Electron/*": [ + "./source/Electron/*" + ], } }, "include": [