-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
postcss.config.mjs
74 lines (71 loc) · 2.37 KB
/
postcss.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { breakpoints as _breakpoints, screens } from './styles/config.mjs'
const validatePixels = (pixels, dimension) => {
const numPixels = Number.parseFloat(pixels)
if (Number.isNaN(numPixels)) {
throw new Error(`Invalid pixel value: ${pixels}`)
}
if (screens[dimension].width === 0 || screens[dimension].height === 0) {
throw new Error(`Screen ${dimension} dimensions cannot be zero`)
}
return numPixels
}
const postcss = {
plugins: {
'postcss-import': {},
'postcss-extend': {},
'postcss-flexbugs-fixes': {},
'postcss-preset-env': {
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
features: {
'custom-properties': false,
},
},
'postcss-nesting': {},
'postcss-include-media': {
breakpoints: {
dt: `${_breakpoints.dt}px`,
},
mediaExpressions: {
hover: '(hover: hover)',
mobile: `(max-width: ${_breakpoints.dt - 1}px)`,
desktop: `(min-width: ${_breakpoints.dt}px)`,
'reduced-motion': '(prefers-reduced-motion: reduce)',
},
},
'postcss-functions': {
functions: {
'mobile-vw': (pixels) => {
const numPixels = validatePixels(pixels, 'mobile')
return `${(numPixels * 100) / screens.mobile.width}vw`
},
'mobile-vh': (pixels) => {
const numPixels = validatePixels(pixels, 'mobile')
const vh = `${(numPixels * 100) / screens.mobile.height}`
return `clamp(${vh}vh, ${vh}svh, ${vh}dvh)`
},
'desktop-vw': (pixels) => {
const numPixels = validatePixels(pixels, 'desktop')
return `${(numPixels * 100) / screens.desktop.width}vw`
},
'desktop-vh': (pixels) => {
const numPixels = validatePixels(pixels, 'desktop')
return `${(numPixels * 100) / screens.desktop.height}svh`
},
columns: (columns) => {
const numColumns = Number.parseFloat(columns)
if (Number.isNaN(numColumns)) {
throw new Error(`Invalid column value: ${columns}`)
}
return `calc((${numColumns} * var(--layout-column-width)) + ((${numColumns} - 1) * var(--layout-columns-gap)))`
},
},
},
'postcss-sort-media-queries': {},
'postcss-combine-duplicated-selectors': {},
cssnano: process.env.NODE_ENV === 'production' ? {} : false,
},
}
export default postcss