Skip to content

Commit

Permalink
Merge branch 'canary' into eslint/next-script-for-ga
Browse files Browse the repository at this point in the history
  • Loading branch information
rgabs committed May 21, 2021
2 parents a9848a3 + 7035a03 commit e12bf22
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/next/build/webpack/config/blocks/css/plugins.ts
Expand Up @@ -42,6 +42,23 @@ function isIgnoredPlugin(pluginPath: string): boolean {
return true
}

const createLazyPostCssPlugin = (
fn: () => import('postcss').AcceptedPlugin
): import('postcss').AcceptedPlugin => {
let result: any = undefined
const plugin = (...args: any[]) => {
if (result === undefined) result = fn() as any
if (result.postcss === true) {
return result(...args)
} else if (result.postcss) {
return result.postcss
}
return result
}
plugin.postcss = true
return plugin
}

async function loadPlugin(
dir: string,
pluginName: string,
Expand All @@ -60,13 +77,13 @@ async function loadPlugin(
if (isIgnoredPlugin(pluginPath)) {
return false
} else if (options === true) {
return require(pluginPath)
return createLazyPostCssPlugin(() => require(pluginPath))
} else {
const keys = Object.keys(options)
if (keys.length === 0) {
return require(pluginPath)
return createLazyPostCssPlugin(() => require(pluginPath))
}
return require(pluginPath)(options)
return createLazyPostCssPlugin(() => require(pluginPath)(options))
}
}

Expand Down

0 comments on commit e12bf22

Please sign in to comment.