fix(webpack): omit postcss plugins for css modules (#14616)
This commit is contained in:
parent
7af4c3faa3
commit
5e2f3154b1
@ -457,7 +457,10 @@ function getCommonLoadersForCssModules(
|
|||||||
loader: require.resolve('postcss-loader'),
|
loader: require.resolve('postcss-loader'),
|
||||||
options: {
|
options: {
|
||||||
implementation: require('postcss'),
|
implementation: require('postcss'),
|
||||||
postcssOptions: postcssOptionsCreator(options, includePaths),
|
postcssOptions: postcssOptionsCreator(options, {
|
||||||
|
includePaths,
|
||||||
|
forCssModules: true,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -478,7 +481,7 @@ function getCommonLoadersForGlobalCss(
|
|||||||
loader: require.resolve('postcss-loader'),
|
loader: require.resolve('postcss-loader'),
|
||||||
options: {
|
options: {
|
||||||
implementation: require('postcss'),
|
implementation: require('postcss'),
|
||||||
postcssOptions: postcssOptionsCreator(options, includePaths),
|
postcssOptions: postcssOptionsCreator(options, { includePaths }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -498,7 +501,7 @@ function getCommonLoadersForGlobalStyle(
|
|||||||
loader: require.resolve('postcss-loader'),
|
loader: require.resolve('postcss-loader'),
|
||||||
options: {
|
options: {
|
||||||
implementation: require('postcss'),
|
implementation: require('postcss'),
|
||||||
postcssOptions: postcssOptionsCreator(options, includePaths),
|
postcssOptions: postcssOptionsCreator(options, { includePaths }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -506,7 +509,10 @@ function getCommonLoadersForGlobalStyle(
|
|||||||
|
|
||||||
function postcssOptionsCreator(
|
function postcssOptionsCreator(
|
||||||
options: NormalizedWebpackExecutorOptions,
|
options: NormalizedWebpackExecutorOptions,
|
||||||
includePaths: string[]
|
{
|
||||||
|
includePaths,
|
||||||
|
forCssModules = false,
|
||||||
|
}: { includePaths: string[]; forCssModules?: boolean }
|
||||||
) {
|
) {
|
||||||
const hashFormat = getOutputHashFormat(options.outputHashing as string);
|
const hashFormat = getOutputHashFormat(options.outputHashing as string);
|
||||||
// PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
|
// PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
|
||||||
@ -523,13 +529,17 @@ function postcssOptionsCreator(
|
|||||||
addModulesDirectories: includePaths,
|
addModulesDirectories: includePaths,
|
||||||
resolve: (url: string) => (url.startsWith('~') ? url.slice(1) : url),
|
resolve: (url: string) => (url.startsWith('~') ? url.slice(1) : url),
|
||||||
}),
|
}),
|
||||||
PostcssCliResources({
|
...(forCssModules
|
||||||
baseHref: options.baseHref,
|
? []
|
||||||
deployUrl: options.deployUrl,
|
: [
|
||||||
loader,
|
PostcssCliResources({
|
||||||
filename: `[name]${hashFormat.file}.[ext]`,
|
baseHref: options.baseHref,
|
||||||
}),
|
deployUrl: options.deployUrl,
|
||||||
autoprefixer(),
|
loader,
|
||||||
|
filename: `[name]${hashFormat.file}.[ext]`,
|
||||||
|
}),
|
||||||
|
autoprefixer(),
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user