Skip to content

Commit 2df5d3b

Browse files
Add optional support for custom postcss plugins
This is accomplished via postcss.config.js, which will be searched for if `plugins` is not specified as an option to `postcss-loader` Postcss plugins are required to use Tailwind CSS, a popular styling framework which leverages a custom module import syntax. This overlaps slightly with facebook#8331, but takes a non-breaking change approach.
1 parent 3190e4f commit 2df5d3b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

docusaurus/docs/advanced-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ You can adjust various development and production settings by setting environmen
2727
| IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | ✅ Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. |
2828
| EXTEND_ESLINT | ✅ Used | ✅ Used | When set to `true`, ESLint configs that extend `eslint-config-react-app` will be used by `eslint-loader`. Any rules that are set to `"error"` will stop the application from building. |
2929
| TSC_COMPILE_ON_ERROR | ✅ Used | ✅ Used | When set to `true`, you can run and properly build TypeScript projects even if there are TypeScript type check errors. These errors are printed as warnings in the terminal and/or browser console. |
30+
| POSTCSS_CONFIG_FILE | ✅ Used | ✅ Used | When set to `true`, you can use a custom `postcss.config.js` in your project, which allows loading custom plugins such as `postcss-import`. |

packages/react-scripts/config/webpack.config.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,23 @@ module.exports = function(webpackEnv) {
110110
// Necessary for external CSS imports to work
111111
// https://github.com/facebook/create-react-app/issues/2677
112112
ident: 'postcss',
113-
plugins: () => [
114-
require('postcss-flexbugs-fixes'),
115-
require('postcss-preset-env')({
116-
autoprefixer: {
117-
flexbox: 'no-2009',
118-
},
119-
stage: 3,
120-
}),
121-
// Adds PostCSS Normalize as the reset css with default options,
122-
// so that it honors browserslist config in package.json
123-
// which in turn let's users customize the target behavior as per their needs.
124-
postcssNormalize(),
125-
],
113+
...(process.env.POSTCSS_CONFIG_FILE === 'true'
114+
? {}
115+
: {
116+
plugins: () => [
117+
require('postcss-flexbugs-fixes'),
118+
require('postcss-preset-env')({
119+
autoprefixer: {
120+
flexbox: 'no-2009',
121+
},
122+
stage: 3,
123+
}),
124+
// Adds PostCSS Normalize as the reset css with default options,
125+
// so that it honors browserslist config in package.json
126+
// which in turn let's users customize the target behavior as per their needs.
127+
postcssNormalize(),
128+
],
129+
}),
126130
sourceMap: isEnvProduction && shouldUseSourceMap,
127131
},
128132
},
@@ -270,8 +274,8 @@ module.exports = function(webpackEnv) {
270274
: false,
271275
},
272276
cssProcessorPluginOptions: {
273-
preset: ['default', { minifyFontValues: { removeQuotes: false } }]
274-
}
277+
preset: ['default', { minifyFontValues: { removeQuotes: false } }],
278+
},
275279
}),
276280
],
277281
// Automatically split vendor and commons

0 commit comments

Comments
 (0)