mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
refactor: use esbuild instead of vite (#2672)
(cherry picked from commit acda594cba)
This commit is contained in:
9
scripts/esbuild/build-plugins.mjs
Executable file
9
scripts/esbuild/build-plugins.mjs
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
import { build } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
await build({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron'],
|
||||
});
|
||||
11
scripts/esbuild/dev-plugins.mjs
Executable file
11
scripts/esbuild/dev-plugins.mjs
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
import { context } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
const plugin = await context({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron'],
|
||||
});
|
||||
|
||||
await plugin.watch();
|
||||
29
scripts/esbuild/utils.mjs
Normal file
29
scripts/esbuild/utils.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export const rootDir = fileURLToPath(new URL('../..', import.meta.url));
|
||||
export const electronOutputDir = resolve(
|
||||
rootDir,
|
||||
'apps',
|
||||
'electron',
|
||||
'dist',
|
||||
'plugins'
|
||||
);
|
||||
export const pluginDir = resolve(rootDir, 'plugins');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pluginDirName {string}
|
||||
* @return {import('esbuild').BuildOptions}
|
||||
*/
|
||||
export function definePluginServerConfig(pluginDirName) {
|
||||
const pluginRootDir = resolve(pluginDir, pluginDirName);
|
||||
const serverEntryFile = resolve(pluginRootDir, 'src/server.ts');
|
||||
const serverOutputDir = resolve(electronOutputDir, pluginDirName);
|
||||
return {
|
||||
entryPoints: [serverEntryFile],
|
||||
platform: 'node',
|
||||
outdir: serverOutputDir,
|
||||
bundle: true,
|
||||
};
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { fileURLToPath } from 'url';
|
||||
import { build } from 'vite';
|
||||
import { beforeAll } from 'vitest';
|
||||
|
||||
export const rootDir = fileURLToPath(new URL('../..', import.meta.url));
|
||||
|
||||
beforeAll(async () => {
|
||||
const { default: config } = await import(
|
||||
resolve(rootDir, './plugins/bookmark-block/vite.config.ts')
|
||||
);
|
||||
await build(config);
|
||||
console.log('Build plugins');
|
||||
await import('../esbuild/build-plugins.mjs');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user