From c2d0272fbc0af49578f5c77ac49e8f5f327074d0 Mon Sep 17 00:00:00 2001 From: Michel Loew Date: Tue, 10 Oct 2023 18:57:15 +0200 Subject: [PATCH 1/4] FEATURE: Add setting to include additional paths for css import path rewrite --- defaults.yaml | 1 + postcss.mjs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/defaults.yaml b/defaults.yaml index fd1c751..34964db 100644 --- a/defaults.yaml +++ b/defaults.yaml @@ -64,6 +64,7 @@ sassOptions: null postcssOptions: tailwindcss: config: './tailwind.config.js' + additionalPackagePathPrefixes: [] esbuild: # Set Neos Flow settings as FLOW variable. If `true` all the settings are passed. diff --git a/postcss.mjs b/postcss.mjs index 06b7960..0079a9b 100644 --- a/postcss.mjs +++ b/postcss.mjs @@ -1,5 +1,6 @@ import path from "path"; import { fs, chokidar, readCache, bold, dim, cyan, magenta } from "carbon-pipeline"; +import { config } from './Lib/helper.mjs' import postcss from "postcss"; import { styleFiles as files, @@ -137,6 +138,13 @@ function build() { } function css(css, file, time) { + const { postcssOptions: { additionalPackagePathPrefixes } = [] } = config; + const combinedPaths = Array.isArray(additionalPackagePathPrefixes) ? additionalPackagePathPrefixes.map(e => { + return `${e}/` + }).join('|') : ''; + + const regexPattern = new RegExp(`(/_Resources/Static/Packages/)(?:${combinedPaths})?([\\w]+.[\\w]+/)Resources/Public/`, 'g'); + return rc() .then((ctx) => { return postcss(ctx.plugins) @@ -155,10 +163,7 @@ function css(css, file, time) { .then((result) => { const tasks = []; // This fixes url done with resolve() - result.css = result.css.replace( - /(\/_Resources\/Static\/Packages\/[\w]+\.[\w]+\/)Resources\/Public\//g, - "$1" - ); + result.css = result.css.replace(regexPattern,"$1$2"); const cssFilesize = humanFileSize(result.css.length); let mapFilesize = 0; From ed199cbed6a0a02bc131e2fa7601aa049d855e73 Mon Sep 17 00:00:00 2001 From: Michel Loew Date: Wed, 11 Oct 2023 08:41:37 +0200 Subject: [PATCH 2/4] TASK: Add documentation for postcss resolve() function --- Readme.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Readme.md b/Readme.md index cf9e4f8..b68a664 100644 --- a/Readme.md +++ b/Readme.md @@ -314,6 +314,32 @@ postcssOptions: prefix: true ``` +#### Use postcss resolve() function +You can use `resolve()` in your css/scss files to load resources (eg images) from `Resources/Public` of the package. The path will be resolved at compile-time. + +``` +.my-class { + background-image: resolve('Images/my-image.jpg') +} +``` + +resolves to +``` +.my-class { + background-image: url('/_Resources/Static/Packages/Your.Package/Images/my-image.jpg') +} +``` + +If you choose to order your Packages in DistributionPackages in sub-folders, you can add this setting to ensure the paths are correctly rewritten: +``` +postcssOptions: + additionalPackagePathPrefixes: + - Sites + - Plugins +``` + +This ensures that the path that is generated (eg `/_Resources/Static/Packages/(Sites|Plugins)/Your.Package/.../`) will be correctly resolved, removing the sub-folder from the path. + #### PostCSS Plugins
From 656d81729707f3e53ea9f9b0b1c1809e93e055c1 Mon Sep 17 00:00:00 2001 From: Jon Uhlmann Date: Wed, 11 Oct 2023 10:03:16 +0200 Subject: [PATCH 3/4] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index b68a664..8b03f69 100644 --- a/Readme.md +++ b/Readme.md @@ -338,7 +338,7 @@ postcssOptions: - Plugins ``` -This ensures that the path that is generated (eg `/_Resources/Static/Packages/(Sites|Plugins)/Your.Package/.../`) will be correctly resolved, removing the sub-folder from the path. +This ensures that the path that is generated (eg `/_Resources/Static/Packages/(Sites|Plugins)/Your.Package/.../`) will be correctly resolved, removing the subfolder from the path. #### PostCSS Plugins From d7a7eccc641c3271df74dfb71435d39f87d0f45c Mon Sep 17 00:00:00 2001 From: Jon Uhlmann Date: Wed, 11 Oct 2023 10:03:22 +0200 Subject: [PATCH 4/4] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 8b03f69..510923a 100644 --- a/Readme.md +++ b/Readme.md @@ -330,7 +330,7 @@ resolves to } ``` -If you choose to order your Packages in DistributionPackages in sub-folders, you can add this setting to ensure the paths are correctly rewritten: +If you choose to order your Packages in DistributionPackages in subfolders, you can add this setting to ensure the paths are correctly rewritten: ``` postcssOptions: additionalPackagePathPrefixes: