fix(webpack): typecheck postcss plugins and add missing postcss-import (resolves #544)

This commit is contained in:
Pooya Parsa 2021-09-21 17:19:54 +02:00
parent e2d216e4ee
commit 57f435a59f
3 changed files with 11 additions and 15 deletions

View File

@ -32,6 +32,7 @@
"mini-css-extract-plugin": "^2.3.0",
"pify": "^5.0.0",
"postcss": "^8.3.6",
"postcss-import": "^14.0.2",
"postcss-import-resolver": "^2.0.0",
"postcss-loader": "^6.1.1",
"postcss-url": "^10.1.3",

View File

@ -3,7 +3,7 @@ import path from 'upath'
import consola from 'consola'
import { defaults, merge, cloneDeep } from 'lodash'
import createResolver from 'postcss-import-resolver'
import { Nuxt, tryRequireModule } from '@nuxt/kit'
import { Nuxt, requireModule } from '@nuxt/kit'
const isPureObject = obj => obj !== null && !Array.isArray(obj) && typeof obj === 'object'
@ -138,20 +138,14 @@ export class PostcssConfig {
}
loadPlugins (config) {
const { plugins } = config
if (isPureObject(plugins)) {
if (!isPureObject(config.plugins)) { return }
// Map postcss plugins into instances on object mode once
config.plugins = this.sortPlugins(config)
.map((p) => {
const plugin = tryRequireModule(p)
const opts = plugins[p]
if (opts === false) {
return false // Disabled
}
return plugin(opts)
})
.filter(Boolean)
}
config.plugins = this.sortPlugins(config).map((pluginName) => {
const pluginFn = requireModule(pluginName, { paths: [__dirname] })
const pluginOptions = config.plugins[pluginName]
if (!pluginOptions || typeof pluginFn !== 'function') { return null }
return pluginFn(pluginOptions)
}).filter(Boolean)
}
config () {

View File

@ -1615,6 +1615,7 @@ __metadata:
mini-css-extract-plugin: ^2.3.0
pify: ^5.0.0
postcss: ^8.3.6
postcss-import: ^14.0.2
postcss-import-resolver: ^2.0.0
postcss-loader: ^6.1.1
postcss-url: ^10.1.3