Skip to content

Commit 0cf16d3

Browse files
authored
update: minify.js — coloring and isDevelopment flag (#279)
update: `minify.js` — coloring and isDevelopment flag
2 parents 2edbc9e + 8cafab8 commit 0cf16d3

File tree

4 files changed

+517
-349
lines changed

4 files changed

+517
-349
lines changed

.eleventy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export default function (eleventyConfig) {
6868
"src/robots.txt": "robots.txt"
6969
})
7070

71+
if (isDevelopment) {
72+
eleventyConfig.addPassthroughCopy({
73+
"src/assets/js": "js",
74+
})
75+
}
76+
7177
eleventyConfig.addFilter("postDate", (dateObj) => {
7278
if (typeof dateObj !== "object") dateObj = new Date(dateObj)
7379
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED)

bin/minify.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import { glob } from "glob";
2+
import chalk from "chalk";
23
import { execSync } from "child_process";
34
import path from "path";
45
import fs from "fs";
56

67
const files = glob.sync("src/assets/js/*.js");
8+
console.log(
9+
`${chalk.gray(`[`)}${chalk.green(`Ew`)}${chalk.gray(`/Terser]`)}`,
10+
chalk.white(`Minifying ${files.length} file(s)`)
11+
);
712
for (const file of files) {
813
const out = path.join("public/js", path.basename(file));
914
fs.mkdirSync(path.dirname(out), { recursive: true });
1015
execSync(`terser "${file}" -o "${out}" -c -m`);
11-
console.log(`Minified: ${file} -> ${out}`);
12-
}
16+
console.log(
17+
`${chalk.gray(`[`)}${chalk.green(`Ew`)}${chalk.gray(`/Terser]`)}`,
18+
chalk.white(`Writing ${out}`),
19+
chalk.gray(`from ${file}`)
20+
);
21+
}
22+
console.log(
23+
`${chalk.gray(`[`)}${chalk.green(`Ew`)}${chalk.gray(`/Terser]`)}`,
24+
chalk.white(`Minification complete ${files.length} file(s)`)
25+
);

0 commit comments

Comments
 (0)