|
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 | + |
2 | 28 | 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')({ |
11 | 37 | preset: 'default',
|
12 |
| - }, |
13 |
| - 'postcss-replace': { |
| 38 | + }), |
| 39 | + require('postcss-replace')({ |
14 | 40 | pattern: /(--tw|\*, ::before, ::after)/g,
|
15 | 41 | data: {
|
16 | 42 | '--tw': '--vuepal-tw',
|
17 | 43 | '*, ::before, ::after': ':root',
|
18 | 44 | },
|
19 |
| - }, |
20 |
| - }, |
| 45 | + }), |
| 46 | + scopePreflight('.vuepal-root'), |
| 47 | + ], |
21 | 48 | }
|
0 commit comments