diff --git a/packages/config/src/options.js b/packages/config/src/options.js index 9d407339b2..fb12f84cbe 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -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')) { diff --git a/packages/webpack/src/utils/postcss.js b/packages/webpack/src/utils/postcss.js index a6c77dfd44..68f4fc52da 100644 --- a/packages/webpack/src/utils/postcss.js +++ b/packages/webpack/src/utils/postcss.js @@ -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 } diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index 3555798026..f7bc4d9809 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -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')]: {} } }