feat(electron): define runtimeConfig in esbuild (#6287)

This commit is contained in:
EYHN
2024-03-25 03:55:26 +00:00
parent d59e1389ec
commit b93871f045
6 changed files with 17 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ async function buildLayers() {
const common = config();
const define: Record<string, string> = {
...common.define,
'process.env.NODE_ENV': `"${mode}"`,
'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`,
};

View File

@@ -1,6 +1,8 @@
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { getRuntimeConfig } from '@affine/cli/src/webpack/runtime-config';
import type { BuildOptions } from 'esbuild';
export const electronDir = fileURLToPath(new URL('..', import.meta.url));
@@ -17,6 +19,15 @@ export const config = (): BuildOptions => {
define['REPLACE_ME_BUILD_ENV'] = `"${process.env.BUILD_TYPE ?? 'stable'}"`;
define['runtimeConfig'] = JSON.stringify(
getRuntimeConfig({
channel: (process.env.BUILD_TYPE as any) ?? 'canary',
distribution: 'desktop',
mode:
process.env.NODE_ENV === 'production' ? 'production' : 'development',
})
);
return {
entryPoints: [
resolve(electronDir, './src/main/index.ts'),

View File

@@ -3,11 +3,11 @@
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"target": "ESNext",
"target": "ES2022",
"module": "ESNext",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"types": ["node"],
"types": ["node", "affine__env"],
"outDir": "lib",
"moduleResolution": "node",
"resolveJsonModule": true,

View File

@@ -9,7 +9,7 @@
"allowSyntheticDefaultImports": true,
"noEmit": false,
"outDir": "./lib/scripts",
"types": ["node"],
"types": ["node", "affine__env"],
"allowJs": true
},
"include": ["./scripts"],

View File

@@ -9,7 +9,7 @@
"allowSyntheticDefaultImports": true,
"noEmit": false,
"outDir": "./lib/tests",
"types": ["node"],
"types": ["node", "affine__env"],
"allowJs": true
},
"references": [