fix(config): let webpack merge postcss plugins (#18839)

This commit is contained in:
Daniel Roe 2023-02-06 14:59:12 -08:00 committed by GitHub
parent 24432058e9
commit 6896e10599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -440,10 +440,8 @@ export function getNuxtConfig (_options) {
delete options.build.crossorigin
}
if (options.build.postcss.plugins) {
if (options.build.postcss?.plugins) {
consola.warn('`postcss.plugins` option has been moved to `postcss.postcssOptions.plugins` for aligning `postcss-loader` format.')
options.build.postcss.postcssOptions.plugins = options.build.postcss.plugins
delete options.build.postcss.plugins
}
if (options.buildModules && options.buildModules.includes('@nuxt/postcss8')) {

View File

@ -195,12 +195,15 @@ export default class PostcssConfig {
// Apply default plugins
if (isPureObject(postcssOptions)) {
const postcssLoaderOptions = this.postcssLoaderOptions
if (postcssLoaderOptions.plugins && !postcssOptions.plugins) {
postcssOptions.plugins = postcssLoaderOptions.plugins
if (postcssLoaderOptions.plugins) {
if (!postcssOptions.plugins || isPureObject(postcssOptions.plugins)) {
postcssOptions.plugins = { ...postcssLoaderOptions.plugins || {}, ...postcssOptions.plugins || {} }
}
delete postcssLoaderOptions.plugins
}
if (postcssLoaderOptions.order && !postcssOptions.order) {
postcssOptions.order = postcssLoaderOptions.order
if ('order' in postcssLoaderOptions) {
// Prioritise correct config value
postcssOptions.order = postcssOptions.order || postcssLoaderOptions.order
delete postcssLoaderOptions.order
}

View File

@ -95,9 +95,12 @@ export default {
'custom-selectors': true
}
},
// deliberately invalid config to test normalization
plugins: {
cssnano: {}
},
postcssOptions: {
plugins: {
cssnano: {},
[path.resolve(__dirname, 'plugins', 'tailwind.js')]: {}
}
}