From fb6ebcd07497f9297cc3371033c2a169ad5f990d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Mon, 8 Jul 2024 15:33:26 +0200 Subject: [PATCH] :bug: Fix debug css being included in prod builds --- frontend/scripts/_helpers.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/scripts/_helpers.js b/frontend/scripts/_helpers.js index a84057a39..4b72301e8 100644 --- a/frontend/scripts/_helpers.js +++ b/frontend/scripts/_helpers.js @@ -27,6 +27,8 @@ export function startWorker() { }); } +export const isDebug = process.env.NODE_ENV !== "production"; + async function findFiles(basePath, predicate, options = {}) { predicate = predicate ?? @@ -75,6 +77,11 @@ export async function compileSass(worker, path, options) { return worker.exec("compileSass", [path, options]); } +export async function compileSassDebug(worker) { + const result = await compileSass(worker, "resources/styles/debug.scss", {}); + return `${result.css}\n`; +} + export async function compileSassAll(worker) { const limitFn = pLimit(4); const sourceDir = "src"; @@ -94,10 +101,7 @@ export async function compileSassAll(worker) { .filter(isDesignSystemFile) .map((path) => ph.join(sourceDir, path)); - const procs = [ - compileSass(worker, "resources/styles/main-default.scss", {}), - compileSass(worker, "resources/styles/debug.scss", {}), - ]; + const procs = [compileSass(worker, "resources/styles/main-default.scss", {})]; for (let path of [...dsFiles, ...appFiles]) { const proc = limitFn(() => compileSass(worker, path, { modules: true })); @@ -176,7 +180,7 @@ async function renderTemplate(path, context = {}, partials = {}) { context = Object.assign({}, context, { ts: ts, - isDebug: process.env.NODE_ENV !== "production", + isDebug, }); return mustache.render(content, context, partials); @@ -401,6 +405,11 @@ export async function compileStyles() { await fs.mkdir("./resources/public/css", { recursive: true }); await fs.writeFile("./resources/public/css/main.css", result); + if (isDebug) { + let debugCSS = await compileSassDebug(worker); + await fs.writeFile("./resources/public/css/debug.css", debugCSS); + } + const end = process.hrtime(start); log.info("done: compile styles", `(${ppt(end)})`); worker.terminate();