From 56a91a9601b0631d55fc0458f115b396fdcdf9d5 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 1 Nov 2022 00:07:25 -0700 Subject: [PATCH] update packaging to create a packaged electron app for frontend --- .gitignore | 3 ++- forge.config.js | 51 ++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- scripthaus.md | 16 +++++++++++++- src/emain.ts | 2 +- webpack.common.js | 2 +- webpack.electron.js | 6 ++++++ 7 files changed, 76 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 02690eefe..ee5bf5009 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules/ *~ *.log out/ -.DS_Store \ No newline at end of file +.DS_Store +bin \ No newline at end of file diff --git a/forge.config.js b/forge.config.js index 9a4060f97..893f79ec6 100644 --- a/forge.config.js +++ b/forge.config.js @@ -1,5 +1,54 @@ +var AllowedFirstParts = { + "package.json": true, + "dist": true, + "static": true, + "node_modules": true, +}; + +var AllowedNodeModules = { + "lzma-native": true, + "fs-ext": true, + "fsevents": true, +}; + +var modCache = {}; + +function ignoreFn(path) { + let parts = path.split("/"); + if (parts.length <= 1) { + return false; + } + let firstPart = parts[1]; + if (!AllowedFirstParts[firstPart]) { + return true; + } + if (firstPart == "node_modules") { + if (parts.length <= 2) { + return false; + } + let nodeModule = parts[2]; + if (!modCache[nodeModule]) { + modCache[nodeModule] = true; + } + if (!AllowedNodeModules[nodeModule]) { + return true; + } + } + return false; +} + module.exports = { - packagerConfig: {}, + packagerConfig: { + ignore: ignoreFn, + files: [ + "package.json", + "dist/*", + "static/*", + "node_modules/lzma-native/**", + "node_modules/fs-ext/**", + "node_modules/fsevents/**", + ], + }, rebuildConfig: {}, makers: [ { diff --git a/package.json b/package.json index dc1feccee..df1c2885a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "sh2", + "name": "ScriptHaus", "version": "1.0.0", "main": "dist/emain-dev.js", "license": "Proprietary", diff --git a/scripthaus.md b/scripthaus.md index 742b32045..639f7c009 100644 --- a/scripthaus.md +++ b/scripthaus.md @@ -6,12 +6,25 @@ node_modules/.bin/webpack --watch --config webpack.dev.js ``` +```bash +# @scripthaus command webpack-build +# @scripthaus cd :playbook +node_modules/.bin/webpack --config webpack.dev.js +``` + + ```bash # @scripthaus command webpack-electron-watch # @scripthaus cd :playbook node_modules/.bin/webpack --watch --config webpack.electron.js ``` +```bash +# @scripthaus command webpack-electron-build +# @scripthaus cd :playbook +node_modules/.bin/webpack --config webpack.electron.js +``` + ```bash # @scripthaus command electron-rebuild # @scripthaus cd :playbook @@ -37,8 +50,9 @@ node_modules/.bin/tsc --jsx preserve --noEmit --esModuleInterop --target ES5 --e ``` ```bash -# @scripthaus command build-js +# @scripthaus command build-package # @scripthaus cd :playbook node_modules/.bin/webpack --config webpack.dev.js node_modules/.bin/webpack --config webpack.electron.js +node_modules/.bin/electron-forge make ``` diff --git a/src/emain.ts b/src/emain.ts index 69bde40b9..100f60813 100644 --- a/src/emain.ts +++ b/src/emain.ts @@ -115,7 +115,7 @@ function createMainWindow(clientData) { width: bounds.width, height: bounds.height, webPreferences: { - preload: path.join(__dirname, "../src/preload.js"), + preload: path.join(__dirname, "../dist/preload.js"), }, }); win.loadFile(path.join(__dirname, "../static/index.html")); diff --git a/webpack.common.js b/webpack.common.js index 7cf28283f..cd1c55b6d 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -57,7 +57,7 @@ module.exports = { ] }, plugins: [ - new MiniCssExtractPlugin({filename: "[name].css", ignoreOrder: true}) + new MiniCssExtractPlugin({filename: "[name].css", ignoreOrder: true}), ], resolve: { extensions: ['.ts', '.tsx', '.js', '.mjs', '.cjs', '.wasm', '.json', '.less', '.css'] diff --git a/webpack.electron.js b/webpack.electron.js index c196251b3..145ff1ce0 100644 --- a/webpack.electron.js +++ b/webpack.electron.js @@ -1,4 +1,5 @@ const path = require("path"); +const CopyPlugin = require("copy-webpack-plugin"); module.exports = { mode: "development", @@ -45,6 +46,11 @@ module.exports = { }, ] }, + plugins: [ + new CopyPlugin({ + patterns: [{from: "src/preload.js", to: "preload.js"}], + }), + ], resolve: { extensions: ['.ts', '.tsx', '.js'] },