fix(vite): sort postcss plugins to add autoprefixer & cssnano last (#3827)

This commit is contained in:
Daniel Roe 2022-03-22 10:40:36 +00:00 committed by GitHub
parent f3168d923b
commit 70f067a14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,28 +4,25 @@ import type { ViteOptions } from './vite'
import { distDir } from './dirs'
export function resolveCSSOptions (nuxt: Nuxt): ViteOptions['css'] {
const css: ViteOptions['css'] = {
const css: ViteOptions['css'] & { postcss: Exclude<ViteOptions['css']['postcss'], string> } = {
postcss: {
plugins: []
}
}
const plugins = nuxt.options.postcss.plugins
for (const name in plugins) {
const opts = plugins[name]
if (!opts) {
continue
}
const plugin = requireModule(name, {
paths: [
...nuxt.options.modulesDir,
distDir
]
const lastPlugins = ['autoprefixer', 'cssnano']
css.postcss.plugins = Object.entries(nuxt.options.postcss.plugins)
.sort((a, b) => lastPlugins.indexOf(a[0]) - lastPlugins.indexOf(b[0]))
.filter(([, opts]) => opts)
.map(([name, opts]) => {
const plugin = requireModule(name, {
paths: [
...nuxt.options.modulesDir,
distDir
]
})
return plugin(opts)
})
// @ts-ignore
css.postcss.plugins.push(plugin(opts))
}
return css
}