[Feature] Добавление поддержки CSS Modules путём использования расширения *.module.css#2294
Merged
[Feature] Добавление поддержки CSS Modules путём использования расширения *.module.css#2294
*.module.css#2294Conversation
*.module.css*.module.css
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a7de844:
|
Contributor
size-limit report 📦
|
Contributor
👀 Styleguide deployedSee the styleguide for this PR at https://vkcom.github.io/VKUI/pull/2294/ |
Contributor
4 tasks
6197ebd to
904c81b
Compare
4 tasks
3 tasks
904c81b to
7582e88
Compare
1 task
4 tasks
7582e88 to
2c8f3f9
Compare
*.module.css*.module.css
2c8f3f9 to
46b1922
Compare
stoope
reviewed
May 25, 2022
Contributor
|
Мы хотим |
Contributor
Author
Отдельной задачей |
stoope
approved these changes
May 31, 2022
SevereCloud
reviewed
May 31, 2022
a5dd1cd to
2609446
Compare
saakovv
approved these changes
Jun 2, 2022
* Update docs * Create getPlatformClassName() * Mark getClassName() deprecated * Extend with `styles` argument next function * getSizeXClassName() * getSizeYClassName() * getHoverClassName() * Changes configs * babel.config.js * postcss.config.js * stylelint.config.js * tsconfig.dist.json * tsconfig.json * webpack.config.js
2609446 to
a7de844
Compare
SevereCloud
approved these changes
Jun 2, 2022
1 task
satandyh
reviewed
Jun 2, 2022
Contributor
satandyh
left a comment
There was a problem hiding this comment.
only for version changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vkuiClassнаclassNameКак работает решение?
Вкратце, для конечной сборки ничего не изменилось, меняется лишь сам подход создания компонентов.
Решение предполагает плавный переход с декоратора
createScopedElementнаCSS Modules.Как было?
Как стало?
На каких компонентах тестировалось?
Какие настройки и инструменты понадобились?
babel-plugin-css-modules-transform
Плагин выгружает CSS классы в объект
Изменения под плагин
babel.config.jskeepImportсохраняет импортирование стилей и, к тому же, заменяет строкуimport styles from './ButtonGroup.modules.css'наimport ./ButtonGroup.modules.css'(используется для командыbabel-cssm).module.cssиз плагинаbabel-plugin-transform-remove-imports– вместо этого удаление импортирования стиле делегирутеся св-вуkeepImportу плагинаcss-modules-transform. Причина: без этогоtransform-remove-importsаффектит плагинcss-modules-transform. Предполагаю первый плагин срабатывает раньше и удаляет имопртирование стилей.typescript-plugin-css-modules
Плагин типизирует CSS классы
Изменения под плагин
.module.css, чтобы TS выкупал иморты такого типаtsconfig.jsonenv.d.tstsconfig.dist.jsonenv.d.tswebpack.config.jsиpostcss.config.jsДля Styleguide появилось дополнительное правило для
.module.css.Здесь мы передаём кастомное св-во в
postcss.config.js, чтобы тут, в плагинеpostcss-modules, мы не подставляли префиксvkuiдля.module.css.Иначе при
import styles from './ButtonGroup.modules.css'вstylesмы будем получатьstyles.vkuiButtonGroup, вместо необходимогоstyles.ButtonGroup.Что стоит учесть?
Новый подход для условных классов: Так как в проекте TS < 4.4.4, для CSS классов нельзя использовать шаблонные строки типаОбновили TS до 4.4.4ButtonGroup--mode-${mode}(в TS > 4.4.4 можно, вот пример)решение для TS < 4.4.4
Вес сборки: Учитывая п. 1 и то, что в сборку будут попадать CSS классы в виде объекта, увеличиться вес сборки.при сжатии в gzip несущественная проблема за счёт алгоритма LZ77.resolve #2607