mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
fix(vite): sort postcss plugins to add autoprefixer & cssnano last (#3827)
This commit is contained in:
parent
f3168d923b
commit
70f067a14b
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user