Skip to content

Commit fb02feb

Browse files
Merge pull request #7 from liip/feature/scope-tailwind-to-vuepal-root
Scope Tailwind base variables to container class
2 parents 680aaeb + 6858922 commit fb02feb

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"postcss-import": "^16.0.1",
7474
"postcss-mixins": "^9.0.4",
7575
"postcss-nested-import": "^1.3.0",
76+
"postcss-prefix-selector": "^2.1.1",
7677
"postcss-replace": "^2.0.1",
7778
"postcss-url": "^10.1.3",
7879
"tailwindcss": "^3.4.1",

postcss.config.cjs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1-
/* eslint-disable */
1+
function scopePreflight(container = '.vuepal-root') {
2+
const creator = () => ({
3+
postcssPlugin: 'scope-preflight',
4+
Once(root) {
5+
root.walkRules((rule) => {
6+
if (!rule.selector) return
7+
const s = rule.selector.replace(/\s+/g, ' ').trim()
8+
const isRootOrHost =
9+
/^:root(?:\s*,\s*:host)?$|^:host(?:\s*,\s*:root)?$/.test(s)
10+
const isUniversal =
11+
/^\*,\s*::?before,\s*::?after(?:,\s*::backdrop)?$/.test(s)
12+
const isBackdrop = /^::backdrop$/.test(s)
13+
14+
if (isRootOrHost) {
15+
rule.selector = container
16+
} else if (isUniversal) {
17+
rule.selector = `${container} *, ${container} ::before, ${container} ::after`
18+
} else if (isBackdrop) {
19+
rule.selector = `${container} ::backdrop`
20+
}
21+
})
22+
},
23+
})
24+
creator.postcss = true
25+
return creator
26+
}
27+
228
module.exports = {
3-
plugins: {
4-
'postcss-import': {},
5-
'postcss-mixins': {},
6-
'postcss-nested-import': {},
7-
'tailwindcss/nesting': {},
8-
'postcss-url': {},
9-
tailwindcss: {},
10-
cssnano: {
29+
plugins: [
30+
require('postcss-import'),
31+
require('postcss-mixins'),
32+
require('postcss-nested-import'),
33+
require('tailwindcss/nesting'),
34+
require('postcss-url'),
35+
require('tailwindcss'),
36+
require('cssnano')({
1137
preset: 'default',
12-
},
13-
'postcss-replace': {
38+
}),
39+
require('postcss-replace')({
1440
pattern: /(--tw|\*, ::before, ::after)/g,
1541
data: {
1642
'--tw': '--vuepal-tw',
1743
'*, ::before, ::after': ':root',
1844
},
19-
},
20-
},
45+
}),
46+
scopePreflight('.vuepal-root'),
47+
],
2148
}

src/runtime/components/VuepalAdminToolbar/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div
33
v-if="data"
4-
class="vuepal-admin-toolbar"
4+
class="vuepal-admin-toolbar vuepal-root"
55
:style="style"
66
@mouseenter="onMouseEnter"
77
@mouseleave="onMouseLeave"

src/runtime/components/VuepalLocalTasks/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="vuepal-local-tasks">
2+
<div class="vuepal-local-tasks vuepal-root">
33
<ul>
44
<li
55
v-for="task in tasks"

tailwind.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = {
55
preflight: false,
66
container: false,
77
},
8-
content: [], // This is important, else unwanted styles will leak.
8+
important: '.vuepal-root',
9+
content: [],
910
theme: {
1011
extend: {
1112
transitionTimingFunction: {

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"extends": "./.nuxt/tsconfig.json",
32
"exclude": ["dist", "node_modules", "playground"]
43
}

0 commit comments

Comments
 (0)