Skip to content

Commit 2b92502

Browse files
committed
Load local PostCSS package if available
1 parent bb0ab67 commit 2b92502

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/cli-peer-dependencies.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export let postcss = require('postcss')
1+
export function lazyPostcss() {
2+
return require('postcss')
3+
}
24

35
export function lazyAutoprefixer() {
46
return require('autoprefixer')

src/cli.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
import { postcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
3+
import { lazyPostcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
44

55
import chokidar from 'chokidar'
66
import path from 'path'
@@ -146,6 +146,15 @@ function oneOf(...options) {
146146
)
147147
}
148148

149+
function loadPostcss() {
150+
// Try to load a local `postcss` version first
151+
try {
152+
return require('postcss')
153+
} catch {}
154+
155+
return lazyPostcss()
156+
}
157+
149158
let commands = {
150159
init: {
151160
run: init,
@@ -576,6 +585,7 @@ async function build() {
576585
})(),
577586
].filter(Boolean)
578587

588+
let postcss = loadPostcss()
579589
let processor = postcss(plugins)
580590

581591
function processCSS(css) {
@@ -709,6 +719,7 @@ async function build() {
709719
let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
710720
let copy = plugins.slice()
711721
copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
722+
let postcss = loadPostcss()
712723
let processor = postcss(copy)
713724

714725
function processCSS(css) {

0 commit comments

Comments
 (0)