Skip to content

Commit

Permalink
Added easy toggle for generating source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Naviary2 committed Jul 11, 2024
1 parent 9478216 commit 258a89d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { readdir, cp as copy, rm as remove, readFile, writeFile } from "node:fs/promises";
import { minify } from "terser";

/** Whether to generate source maps */
const generateMaps = true;

/**
*
* @param {string} path
Expand Down Expand Up @@ -47,17 +50,19 @@ for (const file of clientFiles) {
const filePath = `./dist/${file.replace('./src/client/', '')}`;
const code = await readFile(filePath, 'utf8');
const minified = await minify(code, {
mangle: false, // Disable variable name mangling
mangle: true, // Disable variable name mangling
compress: true, // Enable compression
sourceMap: true
sourceMap: generateMaps
});

filesToWrite.push(
writeFile(filePath, minified.code, 'utf8')
);
filesToWrite.push(
writeFile(filePath + ".map", minified.map, "utf8")
);
if (generateMaps) {
filesToWrite.push(
writeFile(filePath + ".map", minified.map, "utf8")
);
}
}

await Promise.all(filesToWrite);

0 comments on commit 258a89d

Please sign in to comment.