postcss-best-practices
БесплатноБез исполняемых скриптовНе проверенPostCSS best practices and configuration guidelines for modern CSS processing and optimization
от Mindrally★ 323 звезды на GitHubОб этом скилле
PostCSS Best Practices
You are an expert in PostCSS, CSS processing pipelines, and modern CSS tooling.
Key Principles
- Use PostCSS as a modular CSS processor with purpose-specific plugins
- Write future-proof CSS using modern syntax with appropriate transpilation
- Optimize CSS output for production with minification and autoprefixing
- Keep plugin configurations minimal and purposeful
What is PostCSS
PostCSS is a tool for transforming CSS with JavaScript plugins. Unlike preprocessors (Sass/Less), PostCSS:
- Is modular - add only the features you need
- Can parse and transform standard CSS
- Enables future CSS syntax today
- Optimizes and minifies output
- Works with any build tool
Project Setup
Installation
# Core PostCSS
npm install postcss postcss-cli --save-dev
# Common plugins
npm install autoprefixer cssnano postcss-preset-env --save-dev
# Optional plugins
npm install postcss-import postcss-nested postcss-custom-media --save-dev
Configuration File
// postcss.config.js
module.exports = {
plugins: [
require('postcss-import'),
require('postcss-preset-env')({
stage: 2,
features: {
'nesting-rules': true,
'custom-media-queries': true,
'custom-properties': true,
},
}),
require('autoprefixer'),
require('cssnano')({
preset: ['default', {
discardComments: { removeAll: true },
}],
}),
],
};
Build Tool Integration
Webpack
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
],
},
],
},
};
Vite
// vite.config.js
import { defineConfig } from 'vite';
export default defineConfig({
css: {
postcss: './postcss.config.js',
},
});
Next.js
// postcss.config.js (auto-detected)
module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
};
Essential Plugins
postcss-preset-env
Enables modern CSS features with polyfills:
// postcss.config.js
module.exports = {
plugins: [
require('postcss-preset-env')({
stage: 2, // Stage 2 features are stable
features: {
'nesting-rules': true,
'custom-media-queries': true,
'custom-selectors': true,
'gap-properties': true,
'logical-properties-and-values': true,
},
autoprefixer: { grid: true },
browsers: 'last 2 versions',
}),
],
};
autoprefixer
Adds vendor prefixes automatically:
// postcss.config.js
module.exports = {
plugins: [
require('autoprefixer')({
grid: 'autoplace', // Enable grid prefixes
flexbox: true,
}),
],
};
// Input CSS
.element {
display: flex;
user-select: none;
}
// Output CSS
.element {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
cssnano
Minifies and optimizes CSS for production:
// postcss.config.js
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
plugins: [
require('autoprefixer'),
isProduction && require('cssnano')({
preset: ['default', {
discardComments: { removeAll: true },
normalizeWhitespace: true,
minifyFontValues: true,
minifyGradients: true,
reduceIdents: false, // Preserve animation names
mergeRules: true,
mergeLonghand: true,
}],
}),
].filter(Boolean),
};
postcss-import
Inline @import statements:
// postcss.config.js
module.exports = {
plugins: [
require('postcss-import')({
path: ['src/styles'],
}),
],
};
/* main.css */
@import 'variables.css';
@import 'base.css';
@import 'components/buttons.css';
@import 'components/cards.css';
postcss-nested
Enables Sass-like nesting:
// postcss.config.js
module.exports = {
plugins: [
require('postcss-nested'),
],
};
/* Input */
.card {
background: white;
&__header {
padding: 16px;
}
&__body {
padding: 16px;
}
&:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
@media (min-width: 768px) {
display: flex;
}
}
/* Output */
.card {
background: white;
}
.card__header {
padding: 16px;
}
.card__body {
padding: 16px;
}
.card:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
@media (min-width: 768px) {
.card {
display: flex;
}
}
Modern CSS Features
CSS Nesting (Native)
/* Modern browsers support native nesting */
.card {
background: white;
border-radius: 8px;
& .card-header {
padding: 1rem;
border-bottom: 1px solid #eee;
}
& .card-body {
padding
Установить postcss-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл postcss-best-practices?
PostCSS best practices and configuration guidelines for modern CSS processing and optimization
Как установить скилл postcss-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл postcss-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic