Skip to content

Commit

Permalink
fix(customizers/webpack) error in loading postcss loader when using l…
Browse files Browse the repository at this point in the history
…ess in webpack 5
  • Loading branch information
jiangshihai@sisyphe.com.cn committed Aug 5, 2022
1 parent 7e97127 commit 2ad1cc2
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/customizers/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,43 @@ export const addLessLoader = (loaderOptions = {}, customCssModules = {}) => conf
const publicPath = config.output.publicPath;
const shouldUseRelativeAssetPaths = publicPath === "./";

const { version } = require('webpack');
const webpackVersion = version.split(".")[0] * 1

const lessOptions = webpackVersion < 5 ? {
ident: "postcss",
plugins: () => [
require("postcss-flexbugs-fixes"),
require("postcss-preset-env")({
autoprefixer: {
flexbox: "no-2009"
},
stage: 3
}),
postcssNormalize()
],
sourceMap: isEnvProduction && shouldUseSourceMap
} : {
postcssOptions: {
ident: 'postcss',
config: false,
plugins: [
'postcss-flexbugs-fixes',
[
'postcss-preset-env',
{
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
},
],
'postcss-normalize',
]
},
sourceMap: isEnvProduction && shouldUseSourceMap
}

// copy from react-scripts
// https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js#L93
const getStyleLoaders = (cssOptions, preProcessor) => {
Expand All @@ -158,21 +195,8 @@ export const addLessLoader = (loaderOptions = {}, customCssModules = {}) => conf
},
{
loader: require.resolve("postcss-loader"),
options: {
ident: "postcss",
plugins: () => [
require("postcss-flexbugs-fixes"),
require("postcss-preset-env")({
autoprefixer: {
flexbox: "no-2009"
},
stage: 3
}),
postcssNormalize()
],
sourceMap: isEnvProduction && shouldUseSourceMap
}
}
options: lessOptions
},
].filter(Boolean);
if (preProcessor) {
loaders.push(
Expand Down

0 comments on commit 2ad1cc2

Please sign in to comment.