ivanhanloth_Obsidian-Articl.../esbuild.config.mjs
Ivan Hanloth 73c48c9381
feat: create action workflow (#1)
* ci: fix pnpm missing

* ci: fix npm cache error

* ci: add artifact upload

* ci: fix ci undefined

* feat: update package dependencies

* fix: fix ci error

* fix:fix build error

* fix: fix eslint

* fix eslint

* ci: fix eslint error in cicd

* chore: downgrade and pin eslint to v9 to fix typescript-eslint compatibility

* fix: import process module in deploy script

* fix: add JavaScript output files to tsconfig include

* fix: update build output directory from 'out' to 'dist' in workflows and configuration
2026-05-29 14:17:50 +01:00

80 lines
2.1 KiB
JavaScript

import esbuild from "esbuild";
import process from "process";
import { builtinModules } from 'node:module';
import fs from "fs";
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const prod = (process.argv[2] === "production");
// 文件复制插件
const copyManifestPlugin = {
name: 'copy-manifest',
setup(build) {
// onEnd 钩子会在每次构建完成(包括 watch 模式下的重新构建)后触发
build.onEnd(result => {
if (result.errors.length > 0) {
console.log('[copy-plugin] 构建失败,跳过文件复制。');
return;
}
try {
// 确保目标文件夹存在
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist', { recursive: true });
}
// 复制
fs.copyFileSync('main.js', 'dist/main.js');
fs.copyFileSync('manifest.json', 'dist/manifest.json');
fs.copyFileSync('styles.css', 'dist/styles.css');
console.log('[copy-plugin] 静态文件已成功复制到 dist 目录。');
} catch (err) {
console.error('[copy-plugin] 复制文件时出错:', err);
}
});
},
};
const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtinModules],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
plugins: [copyManifestPlugin],
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}