2021-11-21 16:14:46 +00:00
|
|
|
import { requireModule } from '@nuxt/kit'
|
|
|
|
import type { Nuxt } from '@nuxt/schema'
|
2022-02-25 19:11:01 +00:00
|
|
|
import type { ViteOptions } from './vite'
|
2021-10-13 20:08:26 +00:00
|
|
|
import { distDir } from './dirs'
|
|
|
|
|
|
|
|
export function resolveCSSOptions (nuxt: Nuxt): ViteOptions['css'] {
|
2022-08-15 13:40:06 +00:00
|
|
|
const css: ViteOptions['css'] & { postcss: NonNullable<Exclude<NonNullable<ViteOptions['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
|
|
|
|
}
|