refactor: use esbuild instead of vite (#2672)

This commit is contained in:
Himself65
2023-06-02 21:22:09 +08:00
committed by GitHub
parent 94d20f1bdc
commit acda594cba
13 changed files with 111 additions and 80 deletions
+9
View 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
View 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
View 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,
};
}
+2 -10
View File
@@ -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');
});