Skip to content

Собирать CSS вебпаком#1628

Merged
thoughtspile merged 3 commits intomasterfrom
infra/webpack-css
May 27, 2021
Merged

Собирать CSS вебпаком#1628
thoughtspile merged 3 commits intomasterfrom
infra/webpack-css

Conversation

@thoughtspile
Copy link
Copy Markdown
Contributor

@thoughtspile thoughtspile commented May 24, 2021

Продолжаем готовиться к модульным стилям по мотивам #1335 — переносим сборку CSS в вебпак, чтобы дальше потихоньку переносить импорты CSS в tsx-файлы компонент. Стили теперь собираются ~15с, но не думаю что это кого-то сильно расстроит. Это рефакторинговый ПР, сами (собранные) стили не меняются.

@thoughtspile thoughtspile requested a review from a team as a code owner May 24, 2021 18:50
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 24, 2021

size-limit report 📦

Path Size
JS 46.25 KB (0%)
JS, unstable 11.31 KB (0%)
CSS 27.41 KB (+0.14% 🔺)
CSS, unstable 547 B (+7.26% 🔺)

@github-actions
Copy link
Copy Markdown
Contributor

👀 Styleguide deployed

See the styleguide for this PR at https://vkcom.github.io/VKUI/pull/1628/

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented May 24, 2021

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 6dfaa27:

Sandbox Source
VKUI - default example Configuration

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 24, 2021

Code coverage

lines2125 / 360658.93%
statements2167 / 368558.81%
functions484 / 79760.73%
branches1241 / 283043.85%

Generated by 🚫 dangerJS against 6dfaa27

},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js.tmp',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

то есть js будет два раза собираться в итоге?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да. еще есть варики:

  1. собирать бабелем, потом по dist собирать цсс, но тогда вотч превращается в кошмар и вообще это как то нелепо
  2. писать бабель плагин который оставляет только импорты, но это точно не стоит 10 секунд сборки

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да так то ок, просто может тогда и и сборку кода в вебпак унести? (в отдельном пр)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

К сожалению нет =( Из вебпака всегда вылезает один бандл (ну точно не по файлам), и тогда не получится три-шейкать цсс (ради чего всё и затевается), потому что это сайд-эффект импорт. Возможно можно придумать какое-то особо хитрое разбиение 1 компонент = 1 чанк, но пока непонятно станет ли лучше и возможно ли это

ArthurStam
ArthurStam previously approved these changes May 26, 2021
},
{
"selector": "ImportDeclaration[source.value=/\\.css$/i] ~ ImportDeclaration[source.value!=/\\.css$/i]",
"message": "CSS import must be last"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это для консистентности кода?

Copy link
Copy Markdown
Contributor Author

@thoughtspile thoughtspile May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не, это чтобы правильный порядок цсс с одинаковой специфичностью был:

Button.css

.Button {
  border-radius: 3px;
}

Alert.css

.Alert__button {
  border-radius: 0;
}

Alert.tsx

// Button.css первый в CSS-бандле
import { Button } from '../Button/Button'
// Alert.css после всех CSS импортированных компонентов
import './Alert.css'

// Стили для Alert__button оверрайдят базовые стили Button
export const Alert = () => <Button vkuiClass="Alert__button" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants