Open darkfiredarkhalo opened 2 years ago
Did you find methods?
npm run eject
The problem is that the interface of the postcss-loader
has changed, and now the CRA webpack.config.js
nests the loader options in options.postcssOptions
:
while customize-cra
's addPostcssPlugins
looks for options.ident === 'postcss'
instead of options.postcssOptions.ident === 'postcss'
in https://github.com/arackaf/customize-cra/blob/7e97127e530cc6827af66061525e29925e347670/src/customizers/webpack.js#L298.
My fix for now, is to make postcss-loader
from CRA load the postcss.config.js
:
const {
override,
} = require("customize-cra");
const usePostcssRc = () => (config) => {
const rules = config.module.rules.find((rule) => Array.isArray(rule.oneOf)).oneOf;
rules.forEach(
(r) =>
r.use &&
r.use.forEach((u) => {
if (u.options && u.options.postcssOptions && u.options.postcssOptions.ident === 'postcss') {
delete u.options.postcssOptions.plugins;
delete u.options.postcssOptions.config; // this makes the loader load the default config file
}
})
);
return config;
};
module.exports = {
webpack: override(
usePostcssRc(),
),
};
The problem is that the interface of the
postcss-loader
has changed, and now the CRAwebpack.config.js
nests the loader options inoptions.postcssOptions
:while
customize-cra
'saddPostcssPlugins
looks foroptions.ident === 'postcss'
instead ofoptions.postcssOptions.ident === 'postcss'
in. My fix for now, is to make
postcss-loader
from CRA load thepostcss.config.js
:const { override, } = require("customize-cra"); const usePostcssRc = () => (config) => { const rules = config.module.rules.find((rule) => Array.isArray(rule.oneOf)).oneOf; rules.forEach( (r) => r.use && r.use.forEach((u) => { if (u.options && u.options.postcssOptions && u.options.postcssOptions.ident === 'postcss') { delete u.options.postcssOptions.plugins; delete u.options.postcssOptions.config; // this makes the loader load the default config file } }) ); return config; }; module.exports = { webpack: override( usePostcssRc(), ), };
hi, how to load from postcss.config.js, I do like this, but still not work
addPostcssPlugins([
require('@jonny1994/postcss-px-to-viewport')({
unitToConvert: 'px',
viewportWidth: 1920,
viewportUnit: 'rem',
})
]),
usePostcssRc(),
addPostcssPlugins
The problem is that the interface of the
postcss-loader
has changed, and now the CRAwebpack.config.js
nests the loader options inoptions.postcssOptions
: https://github.com/facebook/create-react-app/blob/f34d88e30c7d8be7181f728d1abc4fd8d5cd07d3/packages/react-scripts/config/webpack.config.js#L133-L144 whilecustomize-cra
'saddPostcssPlugins
looks foroptions.ident === 'postcss'
instead ofoptions.postcssOptions.ident === 'postcss'
in https://github.com/arackaf/customize-cra/blob/7e97127e530cc6827af66061525e29925e347670/src/customizers/webpack.js#L298. My fix for now, is to make
postcss-loader
from CRA load thepostcss.config.js
:const { override, } = require("customize-cra"); const usePostcssRc = () => (config) => { const rules = config.module.rules.find((rule) => Array.isArray(rule.oneOf)).oneOf; rules.forEach( (r) => r.use && r.use.forEach((u) => { if (u.options && u.options.postcssOptions && u.options.postcssOptions.ident === 'postcss') { delete u.options.postcssOptions.plugins; delete u.options.postcssOptions.config; // this makes the loader load the default config file } }) ); return config; }; module.exports = { webpack: override( usePostcssRc(), ), };
hi, how to load from postcss.config.js, I do like this, but still not work
addPostcssPlugins([ require('@jonny1994/postcss-px-to-viewport')({ unitToConvert: 'px', viewportWidth: 1920, viewportUnit: 'rem', }) ]), usePostcssRc(),
He wants you to use postcss.config.js not addPostcssPlugins, and I tried it to work
I tested several versions of
react-scripts
and found thataddPostcssPlugins
doesn't work whenreact-scripts
's version higher than or equal to5.0.0
config-overrides.js
: