forked from VKCOM/VKUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postcss.config.js
66 lines (63 loc) · 2.9 KB
/
postcss.config.js
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
const path = require('path');
const cssCustomProperties = require('postcss-custom-properties');
const restructureVariable = require('./packages/postcss-restructure-variable');
const cssImport = require('postcss-import');
const autoprefixer = require('autoprefixer');
const cssModules = require('postcss-modules');
const cssnano = require('cssnano');
const checkKeyframes = require('./packages/postcss-check-keyframes');
const { generateScopedName, cssCustomPropertiesPaths, getCustomMedias } = require('./shared');
const postcssCustomMedia = require('postcss-custom-media');
module.exports = (ctx) => {
const plugins = [
cssImport(),
checkKeyframes({
importFrom: path.join(__dirname, 'src/styles/animations.css'),
}),
cssCustomProperties({
importFrom: cssCustomPropertiesPaths,
preserve: true,
disableDeprecationNotice: true,
}),
restructureVariable(
[
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariables.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBaseDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOS/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOSDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkCom/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkComDark/cssVars/declarations/onlyVariablesLocal.css',
].map((pathSegment) => path.resolve(pathSegment)),
),
autoprefixer(),
cssModules({
generateScopedName: ctx.options.isSandbox ? (name) => name : generateScopedName,
getJSON: () => void 0,
}),
postcssCustomMedia({
importFrom: getCustomMedias,
// см. CONTRIBUTING.md
exportTo: path.resolve('./src/styles/customMedias.generated.css'),
}),
];
if (process.env.NODE_ENV === 'production') {
plugins.push(
cssnano({
preset: [
'default',
{
// Отключаем из-за того, что `postcss-calc` меняет порядок операндов при умножении -1 на переменную
// Подробности здесь https://github.com/VKCOM/VKUI/issues/2963
calc: false,
// Отключаем для webpack-сборки песочницы, т.к. пустые CSS блоки удаляются раньше, чем их обработает
// `css-loader` с настройками для CSS Modules
// Подробности здесь https://github.com/webpack-contrib/css-loader/issues/266
discardEmpty: !ctx.options.isSandbox,
},
],
}),
);
}
return { plugins };
};