Files
twenty_crm/packages/twenty-server/src/utils/generate-front-config.ts
Félix Malfait 9aa24ed803 Compile with swc on twenty-server (#4863)
Experiment using swc instead of tsc (as we did the switch on
twenty-front)

It's **much** faster (at least 5x) but has stricter requirements.
I fixed the build but there's still an error while starting the server,
opening this PR for discussion.

Checkout the branch and try `nx build:swc twenty-server`

Read: https://docs.nestjs.com/recipes/swc#common-pitfalls
2024-04-14 09:09:51 +02:00

36 lines
761 B
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { config } from 'dotenv';
config();
export function generateFrontConfig(): void {
const configObject = {
window: {
_env_: {
REACT_APP_SERVER_BASE_URL: process.env.SERVER_URL,
},
},
};
const configString = `window._env_ = ${JSON.stringify(
configObject.window._env_,
null,
2,
)};`;
const distPath = path.join(__dirname, '../..', 'front');
const filePath = path.join(distPath, 'env-config.js');
if (!fs.existsSync(distPath)) {
fs.mkdirSync(distPath, { recursive: true });
}
if (
!fs.existsSync(filePath) ||
fs.readFileSync(filePath, 'utf8') !== configString
) {
fs.writeFileSync(filePath, configString, 'utf8');
}
}