Skip to content

postcss-import  #1472

Closed
Closed
@seanpanda0

Description

@seanpanda0

Context

In this article about postcss-import.
using-with-preprocessors#build-time-imports

There is an issue with implementing that as described.

Basically @layer and @tailwind(from tailwind) dont play nicely with @import(from postcss-import).

Problems with the article

One you cant use @layer base in a imported file without also declaring @tailwind base in the same file. duplicating the @tailwind base declaration also duplicates tailwinds base css declarations. (some rule applies to the @import 'tailwindcss/base').
You get errors like this Syntax error: /typography.css "@layer base" is used but no matching "@tailwind base" directive is present.

Two declaring @import 'tailwindcss/base' before @import './custom-base.css' does not actually place the css declarations in the right order. the @tailwind declarations seem to be processed after the @imports no mater what order you place them in. the result is tailwindcss/base overrides the custom-base.css despite the order.

Working Solution and postcss-import layer system.

Basically you can use postcss-import layers instead of tailwinds layers and then things are placed in the expected order and you can use @layer inside of imported files.

@import 'tailwindcss/base' layer(Base);
@import './base/typography.css' layer(Base);

@import 'tailwindcss/components' layer(Components);

@import 'tailwindcss/utilities' layer(Utilities);

@layer Base {
  #root {
    @apply some-styles;
  }
}

I would like the postcss-import layer system to be mentioned in that article.
I'd make a PR for the documentation if I was sure where I should put it.

This works a lot better if you're going to be importing css files.

Versions

postcss-import@^14.1.0:
  version "14.1.0"
  resolved "https://registry.npmjs.org/postcss-import/-/postcss-import-14.1.0.tgz"
  
tailwindcss@^3.0.2, tailwindcss@^3.2.4:
  version "3.2.4"
  resolved "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz"
  
react@^18.2.0:
  version "18.2.0"
  resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz"
 

References

Unfortunately I didn't find additional documentation for postcss-import layers.
However you can find examples in under their tests fixtures,
anything with layer in the filename should be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions