|
| 1 | +# Installing PostCSS |
| 2 | + |
| 3 | +[PostCSS Logical Properties and Values] runs in all Node environments, with |
| 4 | +special instructions for: |
| 5 | + |
| 6 | +| [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) | |
| 7 | +| --- | --- | --- | --- | --- | --- | |
| 8 | + |
| 9 | +## Node |
| 10 | + |
| 11 | +Add [PostCSS Logical Properties and Values] to your project: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install postcss-logical --save-dev |
| 15 | +``` |
| 16 | + |
| 17 | +Use [PostCSS Logical Properties and Values] to process your CSS: |
| 18 | + |
| 19 | +```js |
| 20 | +const postcssLogical = require('postcss-logical'); |
| 21 | + |
| 22 | +postcssLogical.process(YOUR_CSS /*, processOptions, pluginOptions */); |
| 23 | +``` |
| 24 | + |
| 25 | +Or use it as a [PostCSS] plugin: |
| 26 | + |
| 27 | +```js |
| 28 | +const postcss = require('postcss'); |
| 29 | +const postcssLogical = require('postcss-logical'); |
| 30 | + |
| 31 | +postcss([ |
| 32 | + postcssLogical(/* pluginOptions */) |
| 33 | +]).process(YOUR_CSS /*, processOptions */); |
| 34 | +``` |
| 35 | + |
| 36 | +## PostCSS CLI |
| 37 | + |
| 38 | +Add [PostCSS CLI] to your project: |
| 39 | + |
| 40 | +```bash |
| 41 | +npm install postcss-cli --save-dev |
| 42 | +``` |
| 43 | + |
| 44 | +Use [PostCSS Logical Properties and Values] in your `postcss.config.js` |
| 45 | +configuration file: |
| 46 | + |
| 47 | +```js |
| 48 | +const postcssLogical = require('postcss-logical'); |
| 49 | + |
| 50 | +module.exports = { |
| 51 | + plugins: [ |
| 52 | + postcssLogical(/* pluginOptions */) |
| 53 | + ] |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +## Webpack |
| 58 | + |
| 59 | +Add [PostCSS Loader] to your project: |
| 60 | + |
| 61 | +```bash |
| 62 | +npm install postcss-loader --save-dev |
| 63 | +``` |
| 64 | + |
| 65 | +Use [PostCSS Logical Properties and Values] in your Webpack configuration: |
| 66 | + |
| 67 | +```js |
| 68 | +const postcssLogical = require('postcss-logical'); |
| 69 | + |
| 70 | +module.exports = { |
| 71 | + module: { |
| 72 | + rules: [ |
| 73 | + { |
| 74 | + test: /\.css$/, |
| 75 | + use: [ |
| 76 | + 'style-loader', |
| 77 | + { loader: 'css-loader', options: { importLoaders: 1 } }, |
| 78 | + { loader: 'postcss-loader', options: { |
| 79 | + ident: 'postcss', |
| 80 | + plugins: () => [ |
| 81 | + postcssLogical(/* pluginOptions */) |
| 82 | + ] |
| 83 | + } } |
| 84 | + ] |
| 85 | + } |
| 86 | + ] |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +## Create React App |
| 92 | + |
| 93 | +Add [React App Rewired] and [React App Rewire PostCSS] to your project: |
| 94 | + |
| 95 | +```bash |
| 96 | +npm install react-app-rewired react-app-rewire-postcss --save-dev |
| 97 | +``` |
| 98 | + |
| 99 | +Use [React App Rewire PostCSS] and [PostCSS Logical Properties and Values] in |
| 100 | +your `config-overrides.js` file: |
| 101 | + |
| 102 | +```js |
| 103 | +const reactAppRewirePostcss = require('react-app-rewire-postcss'); |
| 104 | +const postcssLogical = require('postcss-logical'); |
| 105 | + |
| 106 | +module.exports = config => reactAppRewirePostcss(config, { |
| 107 | + plugins: () => [ |
| 108 | + postcssLogical(/* pluginOptions */) |
| 109 | + ] |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +## Gulp |
| 114 | + |
| 115 | +Add [Gulp PostCSS] to your project: |
| 116 | + |
| 117 | +```bash |
| 118 | +npm install gulp-postcss --save-dev |
| 119 | +``` |
| 120 | + |
| 121 | +Use [PostCSS Logical Properties and Values] in your Gulpfile: |
| 122 | + |
| 123 | +```js |
| 124 | +const postcss = require('gulp-postcss'); |
| 125 | +const postcssLogical = require('postcss-logical'); |
| 126 | + |
| 127 | +gulp.task('css', () => gulp.src('./src/*.css').pipe( |
| 128 | + postcss([ |
| 129 | + postcssLogical(/* pluginOptions */) |
| 130 | + ]) |
| 131 | +).pipe( |
| 132 | + gulp.dest('.') |
| 133 | +)); |
| 134 | +``` |
| 135 | + |
| 136 | +## Grunt |
| 137 | + |
| 138 | +Add [Grunt PostCSS] to your project: |
| 139 | + |
| 140 | +```bash |
| 141 | +npm install grunt-postcss --save-dev |
| 142 | +``` |
| 143 | + |
| 144 | +Use [PostCSS Logical Properties and Values] in your Gruntfile: |
| 145 | + |
| 146 | +```js |
| 147 | +const postcssLogical = require('postcss-logical'); |
| 148 | + |
| 149 | +grunt.loadNpmTasks('grunt-postcss'); |
| 150 | + |
| 151 | +grunt.initConfig({ |
| 152 | + postcss: { |
| 153 | + options: { |
| 154 | + use: [ |
| 155 | + postcssLogical(/* pluginOptions */) |
| 156 | + ] |
| 157 | + }, |
| 158 | + dist: { |
| 159 | + src: '*.css' |
| 160 | + } |
| 161 | + } |
| 162 | +}); |
| 163 | +``` |
| 164 | + |
| 165 | +[Gulp PostCSS]: https://github.com/postcss/gulp-postcss |
| 166 | +[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss |
| 167 | +[PostCSS]: https://github.com/postcss/postcss |
| 168 | +[PostCSS CLI]: https://github.com/postcss/postcss-cli |
| 169 | +[PostCSS Loader]: https://github.com/postcss/postcss-loader |
| 170 | +[PostCSS Logical Properties and Values]: https://github.com/jonathantneal/postcss-logical |
| 171 | +[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss |
| 172 | +[React App Rewired]: https://github.com/timarney/react-app-rewired |
0 commit comments