Skip to content

Commit a0c2ee8

Browse files
authored
Ensure we can use @import 'tailwindcss/...' without node_modules (#8537)
* ensure we can use `@import 'tailwindcss/...'` without node_modules This is useful if you are using `npx tailwindcs ...` and to prevent that postcss-import crashes on the tailwind specific imports which we will replace anyway. * update changelog
1 parent ac91c6a commit a0c2ee8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
3131
- Don't inherit `to` value from parent gradients ([#8489](https://github.com/tailwindlabs/tailwindcss/pull/8489))
3232
- Remove process dependency from log functions ([#8530](https://github.com/tailwindlabs/tailwindcss/pull/8530))
33+
- Ensure we can use `@import 'tailwindcss/...'` without node_modules ([#8537](https://github.com/tailwindlabs/tailwindcss/pull/8537))
3334

3435
### Changed
3536

src/cli.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,17 +568,40 @@ async function build() {
568568

569569
tailwindPlugin.postcss = true
570570

571+
let IMPORT_COMMENT = '__TAILWIND_RESTORE_IMPORT__: '
572+
571573
let [beforePlugins, afterPlugins, postcssOptions] = includePostCss
572574
? await loadPostCssPlugins()
573575
: [
574576
[
577+
(root) => {
578+
root.walkAtRules('import', (rule) => {
579+
if (rule.params.slice(1).startsWith('tailwindcss/')) {
580+
rule.after(postcss.comment({ text: IMPORT_COMMENT + rule.params }))
581+
rule.remove()
582+
}
583+
})
584+
},
575585
(() => {
576586
try {
577587
return require('postcss-import')
578588
} catch {}
579589

580590
return lazyPostcssImport()
581591
})(),
592+
(root) => {
593+
root.walkComments((rule) => {
594+
if (rule.text.startsWith(IMPORT_COMMENT)) {
595+
rule.after(
596+
postcss.atRule({
597+
name: 'import',
598+
params: rule.text.replace(IMPORT_COMMENT, ''),
599+
})
600+
)
601+
rule.remove()
602+
}
603+
})
604+
},
582605
],
583606
[],
584607
{},

0 commit comments

Comments
 (0)