Skip to content

Commit

Permalink
feat(overrides): pass additional arguments to postcss overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Heymdall committed Jul 31, 2024
1 parent 646e5b9 commit 3388ef1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-days-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'arui-scripts': minor
---

Добавлена возможность более тонкой настройки postcss без необходимости полного переопределения плагинов через оверрайды
14 changes: 8 additions & 6 deletions packages/arui-scripts/docs/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export default overrides;
- `postcss` - конфигурация для `postcss`. Ключи: `postcss`.
> `config` postcss содержит массив с уже инициализированными плагинами, параметры которых уже зафиксированны. Если необходимо изменить параметры плагинов можно пересоздать конфиг, таким образом:
```javascript
import {
createPostcssConfig, // функция для создания конфигурационного файла postcss
postcssPlugins, // список плагинов
postcssPluginsOptions, // коллекция конфигураций плагинов
} from 'arui-scripts/build/configs/postcss.config';

module.exports = {
postcss: (config) => {
postcss: (
config,
appConfiguration,
{
createPostcssConfig, // функция для создания конфигурационного файла postcss
postcssPlugins, // список плагинов
postcssPluginsOptions, // коллекция конфигураций плагинов
}) => {
const { files } = postcssPluginsOptions['@csstools/postcss-global-data'];
const newOption = {
...postcssPluginsOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/arui-scripts/src/configs/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createPostcssConfig, postcssPlugins, postcssPluginsOptions } from './po
const postcssConfig = applyOverrides(
'postcss',
createPostcssConfig(postcssPlugins, postcssPluginsOptions),
{ createPostcssConfig, postcssPluginsOptions, postcssPlugins },
);

export default postcssConfig;
7 changes: 7 additions & 0 deletions packages/arui-scripts/src/configs/util/apply-overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ type ServerWebpackAdditionalArgs = {
findPlugin: ReturnType<typeof findPlugin<'server'>>;
};

type PostCssAdditionalArgs = {
createPostcssConfig: (plugins: string[], options: Record<string, unknown>) => string[] | unknown[];
postcssPluginsOptions: Record<string, unknown>;
postcssPlugins: string[];
};

/**
* Дополнительные аргументы, которые будут переданы в функцию оверрайда
*/
Expand All @@ -67,6 +73,7 @@ type OverridesAdditionalArgs = {
webpackServer: ServerWebpackAdditionalArgs;
webpackServerDev: ServerWebpackAdditionalArgs;
webpackServerProd: ServerWebpackAdditionalArgs;
postcss: PostCssAdditionalArgs;
};

type OverrideFunction<
Expand Down
21 changes: 8 additions & 13 deletions packages/example-modules/arui-scripts.overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,15 @@ const overrides: OverrideFile = {
return config;
});
},
postcss: (config) => {
const overridesConfig = config
.map(name => {
if (name !== 'postcss-mixins') return name;
postcss: (config, appConfig, { createPostcssConfig, postcssPluginsOptions, postcssPlugins }) => {
const options = {
...postcssPluginsOptions,
'postcss-mixins': {
mixinsFiles: [path.join(process.cwd(), '../../node_modules/@alfalab/core-components/vars/typography.css')],
},
};

return [
name,
{
mixinsFiles: [path.join(process.cwd(), '../../node_modules/@alfalab/core-components/vars/typography.css')]
}
]
})

return overridesConfig;
return createPostcssConfig(postcssPlugins, options);
}
};

Expand Down
21 changes: 8 additions & 13 deletions packages/example/arui-scripts.overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,15 @@ const overrides: OverrideFile = {
return config;
});
},
postcss: (config) => {
const overridesConfig = config
.map(name => {
if (name !== 'postcss-mixins') return name;
postcss: (config, appConfig, { createPostcssConfig, postcssPluginsOptions, postcssPlugins }) => {
const options = {
...postcssPluginsOptions,
'postcss-mixins': {
mixinsFiles: [path.join(process.cwd(), '../../node_modules/@alfalab/core-components/vars/typography.css')],
},
};

return [
name,
{
mixinsFiles: [path.join(process.cwd(), '../../node_modules/@alfalab/core-components/vars/typography.css')]
}
]
})

return overridesConfig;
return createPostcssConfig(postcssPlugins, options);
}
};

Expand Down

0 comments on commit 3388ef1

Please sign in to comment.