Skip to content

Commit

Permalink
feat(ui): use CSS layer to let user customize app - WF-57
Browse files Browse the repository at this point in the history
We want the user to be able to customize any style using
`import_stylesheet` feature. But, actually, he needs to use `!important`
everywhere to makes his rules have more weight.

The solution is to use CSS cascade layers to redefine the priority of
rules easily. We can move all Writer Framework CSS into a layer `wf`.
This makes other CSS rules have more priority by default.

So I just installed PostCSS and a plugin `postcss-assign-layer`. This
automates surrounding our styles by layers.
  • Loading branch information
madeindjs committed Dec 24, 2024
1 parent 4e956b1 commit ddfae0b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
54 changes: 45 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-storybook": "0.8.0",
"eslint-plugin-vue": "^9.28.0",
"postcss": "^8.4.49",
"postcss-assign-layer": "^0.4.0",
"prettier": "3.2.5",
"storybook": "8.0.5",
"vite": "^5.2.7",
Expand Down
11 changes: 11 additions & 0 deletions src/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fileURLToPath, URL } from "url";
import { defineConfig, UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import writerPlugin from "./viteWriterPlugin";
import postcssAssignLayer from "postcss-assign-layer";

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -11,6 +12,16 @@ export default defineConfig({
define: {
WRITER_LIVE_CCT: JSON.stringify("no"),
},
css: {
postcss: {
plugins: [
// we move all our CSS into Cascade layers to let the user's stylesheets have more priority
postcssAssignLayer([
{ include: "**/*/*.css", layerName: "wf" },
]),
],
},
},
build: {
outDir: "../writer/static",
emptyOutDir: true,
Expand Down

0 comments on commit ddfae0b

Please sign in to comment.