Skip to content

Commit

Permalink
fix: search postcss config from current work dir (#773)
Browse files Browse the repository at this point in the history
fix #770
  • Loading branch information
await-ovo authored Dec 26, 2022
1 parent b107de0 commit 78432e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/esbuild/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path'
import { Loader, Plugin, transform } from 'esbuild'
import { getPostcss } from '../utils'
import type { Result } from 'postcss-load-config';

export const postcssPlugin = ({
css,
Expand All @@ -16,18 +17,18 @@ export const postcssPlugin = ({
name: 'postcss',

setup(build) {
const configCache = new Map()
let configCache: Result

const getPostcssConfig = async (file: string) => {
const getPostcssConfig = async () => {
const loadConfig = require('postcss-load-config')

if (configCache.has(file)) {
return configCache.get(file)
if (configCache) {
return configCache
}

try {
const result = await loadConfig({}, path.dirname(file))
configCache.set(file, result)
const result = await loadConfig({}, process.cwd())
configCache = result
return result
} catch (error: any) {
if (error.message.includes('No PostCSS Config found in')) {
Expand Down Expand Up @@ -87,7 +88,7 @@ export const postcssPlugin = ({
}

// Load postcss config
const { plugins, options } = await getPostcssConfig(args.path)
const { plugins, options } = await getPostcssConfig()

if (plugins && plugins.length > 0) {
// Load postcss
Expand Down
1 change: 0 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module 'rollup-plugin-hashbang'
declare module 'postcss-load-config'

0 comments on commit 78432e2

Please sign in to comment.