Skip to content

Commit d23a493

Browse files
authored
feat(css)!: load postcss config within workspace root only (#18440)
1 parent f2957c8 commit d23a493

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/config/shared-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Inline PostCSS config or a custom directory to search PostCSS config from (defau
217217

218218
For inline PostCSS config, it expects the same format as `postcss.config.js`. But for `plugins` property, only [array format](https://github.com/postcss/postcss-load-config/blob/main/README.md#array) can be used.
219219

220-
The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config) and only the supported config file names are loaded.
220+
The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config) and only the supported config file names are loaded. Config files outside the workspace root (or the [project root](/guide/#index-html-and-project-root) if no workspace is found) are not searched by default. You can specify a custom path outside of the root to load the specific config file instead if needed.
221221

222222
Note if an inline config is provided, Vite will not search for other PostCSS config sources.
223223

packages/vite/src/node/plugins/css.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ import { createBackCompatIdResolver } from '../idResolver'
7979
import type { ResolveIdFn } from '../idResolver'
8080
import { PartialEnvironment } from '../baseEnvironment'
8181
import type { TransformPluginContext } from '../server/pluginContainer'
82-
import type { DevEnvironment } from '..'
82+
import { searchForWorkspaceRoot } from '../server/searchRoot'
83+
import { type DevEnvironment } from '..'
8384
import { addToHTMLProxyTransformResult } from './html'
8485
import {
8586
assetUrlRE,
@@ -1637,7 +1638,8 @@ async function resolvePostcssConfig(
16371638
} else {
16381639
const searchPath =
16391640
typeof inlineOptions === 'string' ? inlineOptions : config.root
1640-
result = postcssrc({}, searchPath).catch((e) => {
1641+
const stopDir = searchForWorkspaceRoot(config.root)
1642+
result = postcssrc({}, searchPath, { stopDir }).catch((e) => {
16411643
if (!e.message.includes('No PostCSS Config found')) {
16421644
if (e instanceof Error) {
16431645
const { name, message, stack } = e

0 commit comments

Comments
 (0)