Skip to content

Commit 67d2286

Browse files
Try using local postcss installation first in the CLI (#8270)
* Load local PostCSS package if available * Update changelog
1 parent d676086 commit 67d2286

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Only check selectors containing base apply candidates for circular dependencies ([#8222](https://github.com/tailwindlabs/tailwindcss/pull/8222))
2222
- Rewrite default class extractor ([#8204](https://github.com/tailwindlabs/tailwindcss/pull/8204))
2323

24+
### Changed
25+
26+
- Try using local `postcss` installation first in the CLI ([#8270](https://github.com/tailwindlabs/tailwindcss/pull/8270))
27+
2428
### Added
2529

2630
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))

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)