mirror of
https://github.com/stracker-phil/obsidian-mention-things.git
synced 2026-07-22 05:43:27 +00:00
78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
import esbuild from 'esbuild';
|
|
import process from 'process';
|
|
import builtins from 'builtin-modules';
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
|
|
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');
|
|
|
|
// Plugin to copy additional files
|
|
const copyFilesToDist = {
|
|
name: 'copy-files',
|
|
setup(build) {
|
|
build.onEnd(async (result) => {
|
|
if (result.errors.length > 0) {
|
|
return;
|
|
}
|
|
|
|
const distDir = path.join(process.cwd(), 'dist');
|
|
|
|
await fs.copy('manifest.json', path.join(distDir, 'manifest.json'));
|
|
|
|
if (await fs.pathExists('styles.css')) {
|
|
await fs.copy('styles.css', path.join(distDir, 'styles.css'));
|
|
}
|
|
|
|
if (await fs.pathExists('resources')) {
|
|
await fs.copy('resources', path.join(distDir, 'resources'));
|
|
}
|
|
|
|
console.log('Copied additional files to /dist folder.');
|
|
});
|
|
},
|
|
};
|
|
|
|
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',
|
|
...builtins,
|
|
],
|
|
format: 'cjs',
|
|
target: 'es2018',
|
|
logLevel: 'info',
|
|
sourcemap: prod ? false : 'inline',
|
|
treeShaking: true,
|
|
outdir: 'dist',
|
|
minify: prod,
|
|
plugins: [copyFilesToDist],
|
|
});
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
}
|