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'
|
|
|
|
|
2024-06-13 22:35:00 +00:00
|
|
|
const lastPlugins = ['autoprefixer', 'cssnano']
|
|
|
|
|
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: {
|
2024-04-05 18:08:32 +00:00
|
|
|
plugins: [],
|
|
|
|
},
|
2021-10-13 20:08:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 22:35:00 +00:00
|
|
|
css.postcss.plugins = []
|
|
|
|
|
|
|
|
const plugins = Object.entries(nuxt.options.postcss.plugins)
|
2022-03-22 10:40:36 +00:00
|
|
|
.sort((a, b) => lastPlugins.indexOf(a[0]) - lastPlugins.indexOf(b[0]))
|
2024-06-13 22:35:00 +00:00
|
|
|
|
|
|
|
for (const [name, opts] of plugins) {
|
|
|
|
if (opts) {
|
2024-06-15 23:03:24 +00:00
|
|
|
// TODO: remove use of requireModule in favour of ESM import
|
2022-03-22 10:40:36 +00:00
|
|
|
const plugin = requireModule(name, {
|
|
|
|
paths: [
|
|
|
|
...nuxt.options.modulesDir,
|
2024-04-05 18:08:32 +00:00
|
|
|
distDir,
|
|
|
|
],
|
2022-03-22 10:40:36 +00:00
|
|
|
})
|
2024-06-13 22:35:00 +00:00
|
|
|
css.postcss.plugins.push(plugin(opts))
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 20:08:26 +00:00
|
|
|
|
|
|
|
return css
|
|
|
|
}
|