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,9 +6,5 @@
"noEmit": false, "noEmit": false,
"outDir": "lib" "outDir": "lib"
}, },
"references": [ "references": []
{
"path": "../../../tests/fixtures"
}
]
} }

View File

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

View File

@@ -1,6 +1,8 @@
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url'; 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'; import type { BuildOptions } from 'esbuild';
export const electronDir = fileURLToPath(new URL('..', import.meta.url)); 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['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 { return {
entryPoints: [ entryPoints: [
resolve(electronDir, './src/main/index.ts'), resolve(electronDir, './src/main/index.ts'),

View File

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

View File

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

View File

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