cli: Add support for CSS exports in package build

This adds support for CSS entry points in package exports. When a package
declares a CSS file in its exports field, the CLI will now automatically
bundle it during `backstage-cli package build` and rewrite the export
path from src/ to dist/ at publish time.

The CSS bundling uses lightningcss to resolve @import statements and
preserves @layer declarations that would otherwise be stripped during
bundling.

This allows packages like @backstage/ui to use the standard build command
instead of custom build scripts for CSS bundling.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Patrik Oldsberg
2026-02-09 13:35:19 +01:00
parent 5a5e9bb6bd
commit 4f9d980943
10 changed files with 122 additions and 9369 deletions
+7 -9
View File
@@ -22,17 +22,18 @@
"sideEffects": [
"*.css"
],
"exports": {
".": "./src/index.ts",
"./css/styles.css": "./src/css/styles.css",
"./package.json": "./package.json"
},
"main": "src/index.ts",
"types": "src/index.ts",
"files": [
"dist",
"css"
"dist"
],
"scripts": {
"build": "yarn build:app && yarn build:css",
"build:app": "backstage-cli package build",
"build:css": "node scripts/build-css.mjs",
"build:css:watch": "node scripts/build-css.mjs --watch",
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
"lint": "backstage-cli package lint",
"prepack": "backstage-cli package prepack",
@@ -50,12 +51,9 @@
"@backstage/cli": "workspace:^",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"chalk": "^5.4.1",
"eslint-plugin-storybook": "^10.3.0-alpha.1",
"glob": "^11.0.1",
"globals": "^15.11.0",
"lightningcss": "^1.29.1",
"mini-css-extract-plugin": "^2.9.2",
"react": "^18.0.2",
"react-dom": "^18.0.2",
"react-router-dom": "^6.30.2",