mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 06:30:45 +08:00
Add unified IM channel plugin
This commit is contained in:
commit
b8bd681a79
26 changed files with 7901 additions and 0 deletions
38
plugin-src/client/build.mjs
Normal file
38
plugin-src/client/build.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { build } from 'esbuild';
|
||||
|
||||
const sourceDirectory = dirname(fileURLToPath(import.meta.url));
|
||||
const packageRoot = resolve(sourceDirectory, '../..');
|
||||
const outputPath = resolve(packageRoot, 'lib/client.js');
|
||||
const loaderId = process.env.DSH_IM_CLIENT_ID ?? '@xmanrui/dsh-im';
|
||||
|
||||
const result = await build({
|
||||
entryPoints: [resolve(sourceDirectory, 'index.js')],
|
||||
bundle: true,
|
||||
format: 'cjs',
|
||||
platform: 'browser',
|
||||
target: ['chrome100'],
|
||||
external: ['react'],
|
||||
write: false,
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
legalComments: 'none',
|
||||
});
|
||||
const bundled = result.outputFiles?.[0]?.text;
|
||||
if (!bundled) throw new Error('esbuild did not produce a client bundle');
|
||||
|
||||
const wrapped = `window.__ModuleLoader__.load({
|
||||
id: ${JSON.stringify(loaderId)},
|
||||
factory: (require) => {
|
||||
var module = { exports: {} };
|
||||
var exports = module.exports;
|
||||
${bundled}
|
||||
return module.exports;
|
||||
}
|
||||
});
|
||||
`;
|
||||
await mkdir(dirname(outputPath), { recursive: true });
|
||||
await writeFile(outputPath, wrapped, 'utf8');
|
||||
console.log(`Wrote ${outputPath}`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue