From a71a506d7ea02a0d26f98b4f9a0c4e044ceb577c Mon Sep 17 00:00:00 2001 From: hpneo Date: Fri, 19 Feb 2021 17:18:32 -0500 Subject: [PATCH] Improve installer template and fix webpack configuration for main process in production environment --- Gemfile.lock | 2 +- .../config/webpack/electron/main/production.js | 6 +++++- lib/install/lib/javascript/babel.js | 12 ++++++------ lib/install/template.rb | 10 ++++++---- lib/webpacker/electron/version.rb | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index abdfee4..8a9b024 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - webpacker-electron (0.1.3) + webpacker-electron (0.1.4) rails (>= 6.0.0) webpacker diff --git a/lib/install/config/webpack/electron/main/production.js b/lib/install/config/webpack/electron/main/production.js index b6e3196..e0fb7b8 100644 --- a/lib/install/config/webpack/electron/main/production.js +++ b/lib/install/config/webpack/electron/main/production.js @@ -4,7 +4,11 @@ const path = require("path"); const { config } = require("@rails/webpacker"); const environment = require("../../environment"); -environment.entry.delete("application"); +Object.keys(environment.entry) + .filter((key) => !key.startsWith("electron")) + .forEach((entry) => { + environment.entry.delete(entry); + }); const electronConfig = { target: "electron-main", diff --git a/lib/install/lib/javascript/babel.js b/lib/install/lib/javascript/babel.js index 0c31043..05b303c 100644 --- a/lib/install/lib/javascript/babel.js +++ b/lib/install/lib/javascript/babel.js @@ -6,12 +6,6 @@ require("@babel/register")({ cwd: path.join(__dirname, "../.."), overrides: [ { - test: path.resolve( - "./", - config.source_path, - config.source_entry_path, - "electron", - ), presets: [ [ "@babel/preset-env", @@ -24,6 +18,12 @@ require("@babel/register")({ }, ], ], + plugins: [ + [ + "module-resolver", + { root: [path.join(__dirname, "../..", config.source_path)] }, + ], + ], }, ], }); diff --git a/lib/install/template.rb b/lib/install/template.rb index 230032d..08858a7 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -39,9 +39,11 @@ append_to_file Rails.root.join(".gitignore") do <<~TEXT + # Electron - public/packs-electron - public/dist + /public/packs-electron + /public/dist + !/public/assets TEXT end @@ -61,8 +63,8 @@ say "Installing all Electron dependencies" -run "yarn add --dev electron electron-builder electron-notarize electron-devtools-installer @babel/register dotenv dotenv-webpack html-webpack-plugin@4.5.1 concurrently cross-env yaml" -run "yarn add electron-updater electron-log electron-debug" +run "yarn add --dev electron-builder electron-notarize @babel/register babel-plugin-module-resolver dotenv dotenv-webpack html-webpack-plugin@4.5.1 concurrently cross-env yaml" +run "yarn add electron electron-devtools-installer electron-updater electron-log electron-debug" run "yarn run electron-builder install-app-deps" say "Webpacker now supports Electron 🎉", :green diff --git a/lib/webpacker/electron/version.rb b/lib/webpacker/electron/version.rb index 5b0dc3b..ec77591 100644 --- a/lib/webpacker/electron/version.rb +++ b/lib/webpacker/electron/version.rb @@ -1,5 +1,5 @@ module Webpacker module Electron - VERSION = '0.1.3' + VERSION = '0.1.4' end end