Skip to content

Commit

Permalink
New webpack.desktop.js configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kidroca committed Feb 15, 2022
1 parent 77361f3 commit 844309e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
11 changes: 5 additions & 6 deletions config/electronBuilder/electronBuilder.local.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ENVIRONMENT = require('../../src/CONST/ENVIRONMENT');
const {version} = require('../../package.json');

const isStaging = process.env.ELECTRON_ENV === 'staging';

Expand All @@ -12,7 +13,7 @@ module.exports = {
appId: 'com.expensifyreactnative.chat',
productName: 'New Expensify',
extraMetadata: {
main: './desktop/main.js',
version,
electronEnvironment: isStaging ? ENVIRONMENT.STAGING : ENVIRONMENT.PRODUCTION,
},
mac: {
Expand All @@ -30,13 +31,11 @@ module.exports = {
internetEnabled: true,
},
files: [
'./dist/**/*',
'./desktop/*.js',
'./src/libs/checkForUpdates.js',
'./src/CONST/ENVIRONMENT.js',
'!**/*/.well-known',
'!**/*/favicon*',
],
directories: {
app: 'desktop',
app: 'desktop/package',
output: 'desktop-build',
},
};
60 changes: 60 additions & 0 deletions config/webpack/webpack.desktop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const path = require('path');
const webpack = require('webpack');
const _ = require('underscore');

const dependencies = require('../../desktop/package/package.json').dependencies;
const webpackWeb = require('./webpack.web');

/**
* Desktop creates 2 configurations in parallel
* 1. electron-main - the core that serves the app content
* 2. web - the app content that would be rendered in electron
* Everything is put together in desktop/package (todo: try to explain why)
* @param {Object} env
* @returns {webpack.Configuration[]}
*/
module.exports = (env) => {
// Reuse web because Desktop is just web served (rendered) locally from Electron
const webConfig = webpackWeb(env);
const outputPath = path.resolve(__dirname, '../../desktop/package/dist');

webConfig.name = 'web';
webConfig.target = 'electron-renderer';
webConfig.output.path = path.join(outputPath, 'www');

const desktopConfig = {
mode: 'production',
name: 'desktop-main',
target: 'electron-main',
entry: {
main: './desktop/main.js',
contextBridge: './desktop/contextBridge.js',
},
output: {
filename: '[name].js',
path: outputPath,
libraryTarget: 'commonjs2',
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
modules: ['src', 'node_modules'],
},
externals: [
..._.keys(dependencies),
'fsevents',
],
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
DEBUG_PROD: false,
START_MINIMIZED: false,
}),
],
node: {
__dirname: false,
__filename: false,
},
};

return [desktopConfig, webConfig];
};
2 changes: 1 addition & 1 deletion desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const electronUpdater = browserWindow => ({
const mainWindow = (() => {
const loadURL = ELECTRON_ENVIRONMENT.isDev()
? win => win.loadURL(`http://localhost:${port}`)
: serve({directory: `${__dirname}/../dist`});
: serve({directory: `${__dirname}/www`});

// Prod and staging set the icon in the electron-builder config, so only update it here for dev
if (ELECTRON_ENVIRONMENT.isDev()) {
Expand Down
8 changes: 3 additions & 5 deletions desktop/package.json → desktop/package/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"name": "new.expensify.desktop",
"version": "untracked",
"description": "Desktop package and dependencies",
"main": "main.js",
"description": "Desktop package native dependencies",
"main": "./dist/main.js",
"scripts": {},
"dependencies": {
"electron-context-menu": "^2.3.0",
"electron-log": "^4.3.5",
"electron-serve": "^1.0.0",
"electron-updater": "^4.3.4",
"underscore": "^1.13.1"
"electron-updater": "^4.3.4"
},
"author": "Expensify, Inc.",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"build": "webpack --config config/webpack/webpack.prod.js",
"build-staging": "webpack --config config/webpack/webpack.staging.js",
"desktop": "export ELECTRON_ENV=development && node desktop/start.js",
"desktop-build": "export ELECTRON_ENV=production && webpack --config config/webpack/webpack.prod.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.ghactions.config.js",
"desktop-build-staging": "export ELECTRON_ENV=staging && webpack --config config/webpack/webpack.staging.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.ghactions.config.js",
"desktop-build-local": "export ELECTRON_ENV=production && webpack --config config/webpack/webpack.prod.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.local.config.js",
"desktop-build-staging-local": "export ELECTRON_ENV=staging && webpack --config config/webpack/webpack.staging.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.local.config.js",
"desktop-build": "export ELECTRON_ENV=production && webpack --config config/webpack/webpack.desktop.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.ghactions.config.js",
"desktop-build-staging": "export ELECTRON_ENV=staging && webpack --config config/webpack/webpack.desktop.js --env envFile=.env.staging && electron-builder --config config/electronBuilder/electronBuilder.ghactions.config.js",
"desktop-build-local": "export ELECTRON_ENV=production && webpack --config config/webpack/webpack.desktop.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.local.config.js",
"desktop-build-staging-local": "export ELECTRON_ENV=staging && webpack --config config/webpack/webpack.desktop.js --platform desktop && electron-builder --config config/electronBuilder/electronBuilder.local.config.js",
"electron-build": "electron-builder --config config/electron.config.js",
"ios-build": "fastlane ios build",
"android-build": "fastlane android build",
Expand Down

0 comments on commit 844309e

Please sign in to comment.