Skip to content

Commit 974ae9f

Browse files
committed
Add postcss-import support to the CLI
1 parent 22f9dc8 commit 974ae9f

File tree

8 files changed

+247
-4
lines changed

8 files changed

+247
-4
lines changed

integrations/tailwindcss-cli/package-lock.json

+109-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrations/tailwindcss-cli/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"build": "NODE_ENV=production node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css",
77
"test": "jest --runInBand --forceExit"
88
},
9+
"dependencies": {
10+
"tailwindcss": "file:../../"
11+
},
912
"jest": {
1013
"testTimeout": 10000,
1114
"displayName": "Tailwind CSS CLI",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@layer utilities {
2+
.something-cool {
3+
color: red;
4+
}
5+
}

integrations/tailwindcss-cli/tests/cli.test.js

+54
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,60 @@ describe('Build command', () => {
345345
expect(contents).toContain(`/*# sourceMappingURL`)
346346
})
347347

348+
test('postcss-import is supported by default', async () => {
349+
cleanupFile('src/test.css')
350+
351+
await writeInputFile('index.html', html`<div class="md:something-cool"></div>`)
352+
await writeInputFile(
353+
'test.css',
354+
css`
355+
@import 'tailwindcss/base';
356+
@import 'tailwindcss/components';
357+
@import 'tailwindcss/utilities';
358+
@import './imported.css';
359+
`
360+
)
361+
362+
await $(
363+
`${EXECUTABLE} --input ./src/test.css --content ./src/index.html --output ./dist/main.css`
364+
)
365+
366+
expect(await readOutputFile('main.css')).toIncludeCss(
367+
css`
368+
@media (min-width: 768px) {
369+
.md\:something-cool {
370+
color: red;
371+
}
372+
}
373+
`
374+
)
375+
})
376+
377+
test('postcss-import is included when using a custom postcss configuration', async () => {
378+
cleanupFile('src/test.css')
379+
380+
await writeInputFile('index.html', html`<div class="md:something-cool"></div>`)
381+
await writeInputFile(
382+
'test.css',
383+
css`
384+
@import 'tailwindcss/base';
385+
@import 'tailwindcss/components';
386+
@import 'tailwindcss/utilities';
387+
@import './imported.css';
388+
`
389+
)
390+
391+
await $(
392+
`${EXECUTABLE} --input ./src/test.css --content ./src/index.html --output ./dist/main.css --postcss`
393+
)
394+
395+
expect(await readOutputFile('main.css')).toIncludeCss(
396+
css`
397+
@import './imported.css';
398+
`
399+
)
400+
})
401+
348402
test('--help', async () => {
349403
let { combined } = await $(`${EXECUTABLE} --help`)
350404

package-lock.json

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"normalize-path": "^3.0.0",
7777
"object-hash": "^3.0.0",
7878
"picocolors": "^1.0.0",
79-
"postcss": "^8.4.13",
79+
"postcss": "^8.0.9",
80+
"postcss-import": "^14.1.0",
8081
"postcss-js": "^4.0.0",
8182
"postcss-load-config": "^3.1.4",
8283
"postcss-nested": "5.0.6",

src/cli-peer-dependencies.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export function lazyPostcss() {
22
return require('postcss')
33
}
44

5+
export function lazyPostcssImport() {
6+
return require('postcss-import')
7+
}
8+
59
export function lazyAutoprefixer() {
610
return require('autoprefixer')
711
}

src/cli.js

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

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

55
import chokidar from 'chokidar'
66
import path from 'path'
@@ -581,7 +581,19 @@ async function build() {
581581

582582
let [beforePlugins, afterPlugins, postcssOptions] = includePostCss
583583
? await loadPostCssPlugins()
584-
: [[], [], {}]
584+
: [
585+
[
586+
(() => {
587+
try {
588+
return require('postcss-import')
589+
} catch {}
590+
591+
return lazyPostcssImport()
592+
})(),
593+
],
594+
[],
595+
{},
596+
]
585597

586598
let plugins = [
587599
...beforePlugins,

0 commit comments

Comments
 (0)