Skip to content

Commit

Permalink
electron config test
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 14, 2023
1 parent 3fb8c35 commit 89ba9f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 1 addition & 3 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ async function createWindow() {
icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
contextIsolation: true,
},
});

Expand Down
22 changes: 18 additions & 4 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path from 'node:path';
import { fileURLToPath } from 'url';

import electron from 'vite-plugin-electron';
import renderer from 'vite-plugin-electron-renderer';
/* import renderer from 'vite-plugin-electron-renderer'; */
import pkg from './package.json';

// Insert utils
Expand Down Expand Up @@ -95,6 +95,7 @@ export default defineConfig(({ command, mode }) => {

const env = loadEnv(mode, process.cwd(), '');
const electronMode = (String(env.ELECTRON_MODE) === 'true');
console.log(`${colors.blue('[vite-config] [electron]')} ${electronMode}`);

const envData = {
mode,
Expand All @@ -106,7 +107,8 @@ export default defineConfig(({ command, mode }) => {
}
};

if (electronMode && mode === 'development') {
/*
if (electronMode && mode === 'development') {
envData.maindir = __dirname;
Expand All @@ -121,13 +123,17 @@ export default defineConfig(({ command, mode }) => {
dest: '',
});
}
*/

copyFiles.targets.push({
src: 'node_modules/@matrix-org/olm/olm.wasm',
dest: '',
});

// Result object
const result = {

appType: 'spa',
publicDir: true,
base: "",

define: {
__ENV_APP__: Object.freeze(envData),
Expand All @@ -146,16 +152,19 @@ export default defineConfig(({ command, mode }) => {

optimizeDeps: {
esbuildOptions: {

define: {
global: 'globalThis'
},

plugins: [
// Enable esbuild polyfill plugins
NodeGlobalsPolyfillPlugin({
process: false,
buffer: true,
}),
]

}
},

Expand Down Expand Up @@ -225,16 +234,21 @@ export default defineConfig(({ command, mode }) => {

]));

/*
result.plugins.push(
// Use Node.js API in the Renderer-process
renderer()
);
*/

}

// Normal
else {

result.appType = 'spa';
result.base = '';

result.build = {
outDir: 'dist',
sourcemap: true,
Expand Down

0 comments on commit 89ba9f4

Please sign in to comment.