Skip to content

Commit

Permalink
🔧 minify js
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0q committed Sep 9, 2024
1 parent 9d31361 commit dc949aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/node": "20.9.0",
"builtin-modules": "4.0.0",
"esbuild": "0.23.1",
"tslib": "2.7.0",
"typescript": "5.5.4"
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 10 additions & 19 deletions scripts/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import path from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
import builtins from "builtin-modules";
import esbuild from "esbuild";
import { context } from "esbuild";

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 isProduction = process.argv[2] === "production";
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const context = await esbuild.context({
banner: {
js: banner,
},
const ctx = await context({
entryPoints: [path.resolve(__dirname, "../src/main.ts")],
minify: isProduction,
bundle: true,
external: ["obsidian", "@electron/remote", ...builtins],
external: ["obsidian", "@electron/remote"],
format: "cjs",
target: "es2018",
target: "es6",
logLevel: "info",
sourcemap: prod ? false : "inline",
sourcemap: isProduction ? false : "inline",
treeShaking: true,
outfile: path.resolve(__dirname, "../main.js"),
});

if (prod) {
await context.rebuild();
if (isProduction) {
await ctx.rebuild();
process.exit(0);
} else {
await context.watch();
await ctx.watch();
}

0 comments on commit dc949aa

Please sign in to comment.