Skip to content

Commit

Permalink
Load local PostCSS package if available
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed May 4, 2022
1 parent bb0ab67 commit 3d53043
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/cli-peer-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export let postcss = require('postcss')
export function lazyPostcss() {
return require('postcss')
}

export function lazyAutoprefixer() {
return require('autoprefixer')
Expand Down
15 changes: 13 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { postcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
import { lazyPostcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'

import chokidar from 'chokidar'
import path from 'path'
Expand Down Expand Up @@ -576,7 +576,18 @@ async function build() {
})(),
].filter(Boolean)

let processor = postcss(plugins)
function loadPostcss() {
// Try to load a local `postcss` version first
try {
if (!process.env.BUILT_IN_POSTCSS) {
return require('postcss')
}
} catch {}

return lazyPostcss()
}

let processor = loadPostcss()(plugins)

function processCSS(css) {
let start = process.hrtime.bigint()
Expand Down

0 comments on commit 3d53043

Please sign in to comment.