From 1f50edc63d8afeb3837fd1c3e40eb6ccace1013d Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Fri, 27 Sep 2024 14:12:05 +0200 Subject: [PATCH] build: update watch methods and include css in build --- apps/delivery-options/package.json | 7 ++-- .../delivery-options/private/skipCssPlugin.ts | 33 +++++++++++++------ nx.json | 1 + package.json | 3 +- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/apps/delivery-options/package.json b/apps/delivery-options/package.json index d201daf4..c66f9133 100644 --- a/apps/delivery-options/package.json +++ b/apps/delivery-options/package.json @@ -32,8 +32,8 @@ "build:dev": "run build:default:dev && run build:myparcel:dev && run build:myparcel-lib:dev", "build:myparcel": "vite build -c vite-myparcel.config.ts", "build:myparcel-lib": "vite build -c vite-myparcel-lib.config.ts", - "build:myparcel-lib:dev": "run build:myparcel-lib -- --mode development", - "build:myparcel:dev": "run build:myparcel -- --mode development", + "build:myparcel-lib:dev": "BUILD_CSS=1 run build:myparcel-lib -- --mode development", + "build:myparcel:dev": "BUILD_CSS=1 run build:myparcel -- --mode development", "clean": "run ws:clean \"$(pwd)\"", "lint": "run ws:lint \"$(pwd)\"", "lint:fix": "run ws:lint:fix \"$(pwd)\"", @@ -46,7 +46,8 @@ "test:run": "run ws:test:run \"$(pwd)\"", "test:update": "run ws:test:update \"$(pwd)\"", "typecheck": "vue-tsc --project tsconfig.base.json --noEmit", - "watch": "vite build -c vite-myparcel-lib.config.ts --mode development --watch" + "watch:myparcel": "BUILD_CSS=1 vite build -c vite-myparcel-lib.config.ts --watch --mode development", + "watch:myparcel-lib": "BUILD_CSS=1 vite build -c vite-myparcel.config.ts --watch --mode development" }, "dependencies": { "@myparcel-do/shared": "workspace:*", diff --git a/apps/delivery-options/private/skipCssPlugin.ts b/apps/delivery-options/private/skipCssPlugin.ts index 7d55931c..548aae64 100644 --- a/apps/delivery-options/private/skipCssPlugin.ts +++ b/apps/delivery-options/private/skipCssPlugin.ts @@ -1,12 +1,25 @@ -import {type Plugin} from 'vite'; +import {type Plugin, createLogger} from 'vite'; -export const skipCssPlugin = (): Plugin => ({ - name: 'skip-css', - transform(_, id) { - if (id.endsWith('.scss') || id.endsWith('.css')) { - return ''; - } +const PLUGIN_NAME = 'skip-css'; +export const skipCssPlugin = (): Plugin => { + const buildAnyway = Boolean(process.env.BUILD_CSS ?? false); + + const logger = createLogger(undefined, {prefix: PLUGIN_NAME}); + + if (buildAnyway) { + logger.info('Building CSS files because BUILD_CSS is set.'); + } - return null; - }, -}); + return { + name: PLUGIN_NAME, + transform(_, id) { + const isCssFile = id.endsWith('.scss') || id.endsWith('.css'); + + if (buildAnyway || !isCssFile) { + return null; + } + + return ''; + }, + }; +}; diff --git a/nx.json b/nx.json index 87dff924..ed1dc65e 100644 --- a/nx.json +++ b/nx.json @@ -16,6 +16,7 @@ "{projectRoot}/*.json", "{projectRoot}/*.mjs", "{projectRoot}/*.ts", + "{projectRoot}/private/**/*", "{projectRoot}/public/**/*", "{projectRoot}/src/**/*", "!{projectRoot}/release.config.cjs", diff --git a/package.json b/package.json index 84a5f619..31adf474 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "test:update": "nx run-many -t test:update --output-style=stream", "translations:import": "yarn workspace @myparcel-do/sandbox run translations:import", "typecheck": "nx run-many -t typecheck", - "watch": "nx run-many -t watch --output-style=stream --parallel=99", + "watch": "nx run-many -t watch:myparcel --output-style=stream --parallel=99", + "watch:lib": "nx run-many -t watch:myparcel-lib --output-style=stream --parallel=99", "ws:clean": "cd $0 && rimraf dist coverage .eslintcache tsconfig.build.tsbuildinfo", "ws:lint": "eslint --cache $0", "ws:lint:fix": "eslint --cache --fix $0",