Skip to content

Commit 78432e2

Browse files
authoredDec 26, 2022
fix: search postcss config from current work dir (#773)
fix #770
1 parent b107de0 commit 78432e2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
 

‎src/esbuild/postcss.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33
import { Loader, Plugin, transform } from 'esbuild'
44
import { getPostcss } from '../utils'
5+
import type { Result } from 'postcss-load-config';
56

67
export const postcssPlugin = ({
78
css,
@@ -16,18 +17,18 @@ export const postcssPlugin = ({
1617
name: 'postcss',
1718

1819
setup(build) {
19-
const configCache = new Map()
20+
let configCache: Result
2021

21-
const getPostcssConfig = async (file: string) => {
22+
const getPostcssConfig = async () => {
2223
const loadConfig = require('postcss-load-config')
2324

24-
if (configCache.has(file)) {
25-
return configCache.get(file)
25+
if (configCache) {
26+
return configCache
2627
}
2728

2829
try {
29-
const result = await loadConfig({}, path.dirname(file))
30-
configCache.set(file, result)
30+
const result = await loadConfig({}, process.cwd())
31+
configCache = result
3132
return result
3233
} catch (error: any) {
3334
if (error.message.includes('No PostCSS Config found in')) {
@@ -87,7 +88,7 @@ export const postcssPlugin = ({
8788
}
8889

8990
// Load postcss config
90-
const { plugins, options } = await getPostcssConfig(args.path)
91+
const { plugins, options } = await getPostcssConfig()
9192

9293
if (plugins && plugins.length > 0) {
9394
// Load postcss

‎types.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
declare module 'rollup-plugin-hashbang'
2-
declare module 'postcss-load-config'

0 commit comments

Comments
 (0)
Please sign in to comment.