Skip to content

Commit

Permalink
perf: lazy load postcss-load-config
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 4, 2020
1 parent ea5eb19 commit 1e8b584
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ type Result = ReturnType<typeof postcssrc> extends Promise<infer T> ? T : never
let cachedPostcssConfig: Result | null | undefined

export async function loadPostcssConfig(root: string): Promise<Result | null> {
if (cachedPostcssConfig !== undefined) {
return cachedPostcssConfig
}
try {
return (
cachedPostcssConfig || (cachedPostcssConfig = await postcssrc({}, root))
)
const load = require('postcss-load-config') as typeof postcssrc
return (cachedPostcssConfig = await load({}, root))
} catch (e) {
return (cachedPostcssConfig = null)
}
Expand Down

0 comments on commit 1e8b584

Please sign in to comment.