Generate build artifacts into a separate folder. on new version, copy the manifest.json file into the build folder
This commit is contained in:
parent
49fba8aa1f
commit
0274e7a26e
|
@ -1,42 +1,65 @@
|
||||||
import esbuild from "esbuild";
|
import process from "node:process";
|
||||||
import process from "process";
|
import path from "node:path";
|
||||||
import builtins from 'builtin-modules'
|
import { copyFileSync } from "node:fs";
|
||||||
|
|
||||||
const banner =
|
import esbuild from "esbuild";
|
||||||
`/*
|
import builtins from "builtin-modules";
|
||||||
|
|
||||||
|
const banner = `/*
|
||||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||||
if you want to view the source, please visit the github repository of this plugin
|
if you want to view the source, please visit the github repository of this plugin
|
||||||
*/
|
*/
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const prod = (process.argv[2] === 'production');
|
const prod = process.argv[2] === "production";
|
||||||
|
|
||||||
esbuild.build({
|
const buildOptions = {
|
||||||
banner: {
|
banner: {
|
||||||
js: banner,
|
js: banner,
|
||||||
},
|
},
|
||||||
entryPoints: ['main.ts'],
|
entryPoints: ["main.ts", "styles.css"],
|
||||||
|
outdir: "dist",
|
||||||
bundle: true,
|
bundle: true,
|
||||||
external: [
|
external: [
|
||||||
'obsidian',
|
"obsidian",
|
||||||
'electron',
|
"electron",
|
||||||
'@codemirror/autocomplete',
|
"@codemirror/autocomplete",
|
||||||
'@codemirror/collab',
|
"@codemirror/collab",
|
||||||
'@codemirror/commands',
|
"@codemirror/commands",
|
||||||
'@codemirror/language',
|
"@codemirror/language",
|
||||||
'@codemirror/lint',
|
"@codemirror/lint",
|
||||||
'@codemirror/search',
|
"@codemirror/search",
|
||||||
'@codemirror/state',
|
"@codemirror/state",
|
||||||
'@codemirror/view',
|
"@codemirror/view",
|
||||||
'@lezer/common',
|
"@lezer/common",
|
||||||
'@lezer/highlight',
|
"@lezer/highlight",
|
||||||
'@lezer/lr',
|
"@lezer/lr",
|
||||||
...builtins],
|
...builtins,
|
||||||
format: 'cjs',
|
],
|
||||||
|
format: "cjs",
|
||||||
watch: !prod,
|
watch: !prod,
|
||||||
target: 'es2018',
|
target: "es2018",
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
sourcemap: prod ? false : 'inline',
|
sourcemap: prod ? false : "inline",
|
||||||
treeShaking: true,
|
treeShaking: true,
|
||||||
outfile: 'main.js',
|
};
|
||||||
}).catch(() => process.exit(1));
|
|
||||||
|
esbuild
|
||||||
|
.build(buildOptions)
|
||||||
|
.catch(() => process.exit(1))
|
||||||
|
.then(() => {
|
||||||
|
/**
|
||||||
|
* If there is a new version number, copy it to the dist folder
|
||||||
|
*/
|
||||||
|
if (process.env.npm_new_version) {
|
||||||
|
const manifestJsonSrc = path.join(process.cwd(), "manifest.json");
|
||||||
|
const manifestJsonDist = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
buildOptions.outdir,
|
||||||
|
"manifest.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copy the manifest.json file over to the dist folder
|
||||||
|
copyFileSync(manifestJsonSrc, manifestJsonDist);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue