2021-11-21 16:14:46 +00:00
|
|
|
import { requireModule } from '@nuxt/kit'
|
|
|
|
import type { Nuxt } from '@nuxt/schema'
|
2023-03-29 10:59:57 +00:00
|
|
|
import type { InlineConfig as ViteConfig } from 'vite'
|
2021-10-13 20:08:26 +00:00
|
|
|
import { distDir } from './dirs'
|
|
|
|
|
2023-03-29 10:59:57 +00:00
|
|
|
export function resolveCSSOptions (nuxt: Nuxt): ViteConfig['css'] {
|
|
|
|
const css: ViteConfig['css'] & { postcss: NonNullable<Exclude<NonNullable<ViteConfig['css']>['postcss'], string>> } = {
|
2021-10-13 20:08:26 +00:00
|
|
|
postcss: {
|
|
|
|
plugins: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 10:40:36 +00:00
|
|
|
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)
|
2021-10-13 20:08:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return css
|
|
|
|
}
|