Integration Guide
PostCSS Logical Polyfill can be easily integrated with various build tools and frameworks. This guide covers the most common setups.
PostCSS CLI
Section titled “PostCSS CLI”The simplest way to use the plugin with PostCSS CLI:
- Install the dependencies:
npm install postcss postcss-cli postcss-logical-polyfill
- Create a
postcss.config.js
:
module.exports = { plugins: [ require('postcss-logical-polyfill')({ preserve: false }) ]}
- Run PostCSS:
npx postcss input.css -o output.css
Webpack
Section titled “Webpack”To integrate with Webpack, add the plugin to your PostCSS loader configuration:
module.exports = { module: { rules: [ { test: /\.css$/, use: [ 'style-loader', 'css-loader', { loader: 'postcss-loader', options: { postcssOptions: { plugins: [ ['postcss-logical-polyfill', { preserve: false, dir: 'ltr' }] ] } } } ] } ] }}
For Vite projects, add the plugin to your vite.config.js
:
import { defineConfig } from 'vite'
export default defineConfig({ css: { postcss: { plugins: [ require('postcss-logical-polyfill')({ preserve: false }) ] } }})
Next.js
Section titled “Next.js”In Next.js projects, create or update your postcss.config.js
:
module.exports = { plugins: [ 'postcss-flexbugs-fixes', 'postcss-logical-polyfill', [ 'postcss-preset-env', { autoprefixer: { flexbox: 'no-2009' }, stage: 3, features: { 'custom-properties': false } } ] ]}
Sass/SCSS Integration
Section titled “Sass/SCSS Integration”When using with Sass, ensure PostCSS processes the compiled CSS:
module.exports = { module: { rules: [ { test: /\.scss$/, use: [ 'style-loader', 'css-loader', { loader: 'postcss-loader', options: { postcssOptions: { plugins: [ 'postcss-logical-polyfill' ] } } }, 'sass-loader' ] } ] }}
Less Integration
Section titled “Less Integration”Similar to Sass, ensure PostCSS runs after Less compilation:
module.exports = { module: { rules: [ { test: /\.less$/, use: [ 'style-loader', 'css-loader', { loader: 'postcss-loader', options: { postcssOptions: { plugins: [ 'postcss-logical-polyfill' ] } } }, 'less-loader' ] } ] }}
Gulp Integration
Section titled “Gulp Integration”For Gulp-based builds:
const gulp = require('gulp')const postcss = require('gulp-postcss')const logicalPolyfill = require('postcss-logical-polyfill')
gulp.task('css', () => { return gulp.src('src/**/*.css') .pipe(postcss([ logicalPolyfill({ preserve: false }) ])) .pipe(gulp.dest('dist'))})
Rollup Integration
Section titled “Rollup Integration”With Rollup and rollup-plugin-postcss:
import postcss from 'rollup-plugin-postcss'import logicalPolyfill from 'postcss-logical-polyfill'
export default { plugins: [ postcss({ plugins: [ logicalPolyfill({ preserve: false }) ] }) ]}
Framework-Specific Considerations
Section titled “Framework-Specific Considerations”React Applications
Section titled “React Applications”For Create React App projects, you’ll need to eject or use CRACO to customize the PostCSS configuration:
module.exports = { style: { postcss: { plugins: [ require('postcss-logical-polyfill')({ preserve: false }) ] } }}
Vue.js
Section titled “Vue.js”In Vue CLI projects, add to vue.config.js
:
module.exports = { css: { loaderOptions: { postcss: { plugins: [ require('postcss-logical-polyfill')({ preserve: false }) ] } } }}
Angular
Section titled “Angular”For Angular projects, add to angular.json
or create a custom PostCSS config:
{ "projects": { "your-app": { "architect": { "build": { "options": { "postcssConfig": "./postcss.config.js" } } } } }}
Common Issues and Solutions
Section titled “Common Issues and Solutions”Plugin Order
Section titled “Plugin Order”Always place postcss-logical-polyfill before autoprefixer to ensure proper vendor prefix handling.
CSS-in-JS Solutions
Section titled “CSS-in-JS Solutions”For styled-components or emotion, you may need to process CSS at build time or use a custom PostCSS setup.
Hot Module Replacement
Section titled “Hot Module Replacement”Some development servers may cache transformed CSS. Restart the development server if changes aren’t reflected.
Performance Optimization
Section titled “Performance Optimization”For production builds, consider:
- Setting
preserve: false
to reduce output size - Using with other PostCSS optimizations like cssnano
- Enabling source maps for debugging during development
// Production configmodule.exports = { plugins: [ require('postcss-logical-polyfill')({ preserve: false }), require('cssnano')({ preset: 'default' }) ]}