mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-22 21:51:39 +03:00
b15ae21c45
Should greatly reduce the size of helper.js and could speed up the time on starting the client app. fix https://github.com/toeverything/AFFiNE/issues/6312 Before: ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/681d6766-7d48-4574-b791-49e2c0ae6e1b.png) After: ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/ab13e624-7e03-407d-9538-3b9452694402.png)
40 lines
905 B
TypeScript
40 lines
905 B
TypeScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
import { config, mode, rootDir } from './common';
|
|
|
|
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'}"`,
|
|
};
|
|
|
|
if (process.env.BUILD_TYPE_OVERRIDE) {
|
|
define['process.env.BUILD_TYPE_OVERRIDE'] =
|
|
`"${process.env.BUILD_TYPE_OVERRIDE}"`;
|
|
}
|
|
|
|
const metafile = process.env.METAFILE;
|
|
|
|
const result = await esbuild.build({
|
|
...common,
|
|
define: define,
|
|
metafile: !!metafile,
|
|
});
|
|
|
|
if (metafile) {
|
|
await fs.writeFile(
|
|
path.resolve(rootDir, `metafile-${Date.now()}.json`),
|
|
JSON.stringify(result.metafile, null, 2)
|
|
);
|
|
}
|
|
}
|
|
|
|
await buildLayers();
|
|
console.log('Build layers done');
|