|
|
@@ -1,3 +1,4 @@
|
|
|
+console.time("Build time");
|
|
|
import esbuild from "esbuild";
|
|
|
import htmlMinifier from "html-minifier-terser";
|
|
|
import fsSync from "fs";
|
|
|
@@ -8,12 +9,12 @@ const isProduction = process.env.NODE_ENV === "production";
|
|
|
const esbuildProm = esbuild.build({
|
|
|
entryPoints: [`${import.meta.dirname}/js/index.js`, `${import.meta.dirname}/css/index.css`],
|
|
|
bundle: true,
|
|
|
- minify: true,
|
|
|
+ minify: isProduction,
|
|
|
sourcemap: isProduction ? false : "inline",
|
|
|
write: false,
|
|
|
- outdir: `${import.meta.dirname}`
|
|
|
+ outdir: import.meta.dirname
|
|
|
});
|
|
|
-const htmlProm = fs.readFile(`${import.meta.dirname}/index.html`, "utf-8");
|
|
|
+const htmlProm = await fs.readFile(`${import.meta.dirname}/index.html`, "utf-8");
|
|
|
const [build, html] = await Promise.all([esbuildProm, htmlProm]);
|
|
|
|
|
|
let js, css;
|
|
|
@@ -38,4 +39,5 @@ let data = await htmlMinifier.minify(html, {
|
|
|
data = data.replace("<script></script>", `<script>${js}</script>`)
|
|
|
data = data.replace("<style></style>", `<style>${css}</style>`)
|
|
|
|
|
|
-fs.writeFile(`${import.meta.dirname}/build.html`, data);
|
|
|
+await fs.writeFile(`${import.meta.dirname}/build.html`, data);
|
|
|
+console.timeEnd("Build time");
|