Skip to content

Commit 0f49c47

Browse files
authoredOct 21, 2022
feat(bundler-vite): auto load postcss plugins from postcss config files (#1088)
1 parent f1947f4 commit 0f49c47

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
 

‎packages/bundler-vite/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"autoprefixer": "^10.4.11",
4242
"connect-history-api-fallback": "^2.0.0",
4343
"postcss": "^8.4.16",
44+
"postcss-load-config": "^4.0.1",
4445
"rollup": "^2.79.0",
4546
"vite": "~3.1.1",
4647
"vue": "^3.2.39",

‎packages/bundler-vite/src/plugins/mainPlugin.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { App } from '@vuepress/core'
22
import { fs } from '@vuepress/utils'
33
import autoprefixer from 'autoprefixer'
44
import history from 'connect-history-api-fallback'
5+
import type { AcceptedPlugin } from 'postcss'
6+
import postcssrc from 'postcss-load-config'
57
import type { AliasOptions, Connect, Plugin, UserConfig } from 'vite'
68

79
/**
@@ -48,6 +50,14 @@ import '@vuepress/client/app'
4850
.map(({ name }) => name),
4951
]
5052

53+
let postcssPlugins: AcceptedPlugin[]
54+
try {
55+
const postcssConfigResult = await postcssrc()
56+
postcssPlugins = postcssConfigResult.plugins
57+
} catch (error) {
58+
postcssPlugins = [autoprefixer]
59+
}
60+
5161
return {
5262
root: app.dir.temp('vite-root'),
5363
base: app.options.base,
@@ -60,7 +70,7 @@ import '@vuepress/client/app'
6070
},
6171
css: {
6272
postcss: {
63-
plugins: isServer ? [] : [autoprefixer],
73+
plugins: isServer ? [] : postcssPlugins,
6474
},
6575
preprocessorOptions: {
6676
scss: { charset: false },

‎pnpm-lock.yaml

+24-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.