Skip to content

Commit

Permalink
feat(css)!: load postcss config within workspace root only (#18440)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 24, 2024
1 parent f2957c8 commit d23a493
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/config/shared-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Inline PostCSS config or a custom directory to search PostCSS config from (defau

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.

The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config) and only the supported config file names are loaded.
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.

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

Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ import { createBackCompatIdResolver } from '../idResolver'
import type { ResolveIdFn } from '../idResolver'
import { PartialEnvironment } from '../baseEnvironment'
import type { TransformPluginContext } from '../server/pluginContainer'
import type { DevEnvironment } from '..'
import { searchForWorkspaceRoot } from '../server/searchRoot'
import { type DevEnvironment } from '..'
import { addToHTMLProxyTransformResult } from './html'
import {
assetUrlRE,
Expand Down Expand Up @@ -1637,7 +1638,8 @@ async function resolvePostcssConfig(
} else {
const searchPath =
typeof inlineOptions === 'string' ? inlineOptions : config.root
result = postcssrc({}, searchPath).catch((e) => {
const stopDir = searchForWorkspaceRoot(config.root)
result = postcssrc({}, searchPath, { stopDir }).catch((e) => {
if (!e.message.includes('No PostCSS Config found')) {
if (e instanceof Error) {
const { name, message, stack } = e
Expand Down

0 comments on commit d23a493

Please sign in to comment.