Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple configuration rules #1

Closed
sambedingfield opened this issue Feb 12, 2024 · 4 comments · Fixed by #2
Closed

Multiple configuration rules #1

sambedingfield opened this issue Feb 12, 2024 · 4 comments · Fixed by #2

Comments

@sambedingfield
Copy link

sambedingfield commented Feb 12, 2024

Thanks for the great plugin - especially to fix vitejs/vite#3924 when using lazy loaded components in Vite.

What's the preferred way to handle multiple rules, if possible?

To avoid another config I have my postcss set in my vite.config, which has to use the Array formatting, and this seems to work.

postcss: {
  plugins: [
    require('postcss-assign-layer')({
      include: '**/styles/**.{css,scss}',
      layerName: 'base',
    }),
    require('postcss-assign-layer')({
      include: '**/components/**/*.{css,scss}',
      layerName: 'components',
    }),
    require('postcss-assign-layer')({
      include: '**/templates/**.{css,scss}',
      layerName: 'templates',
    }),
  ]      
},
@IanVS
Copy link
Collaborator

IanVS commented Feb 12, 2024

Hey, I'm glad this is useful for you. I actually didn't consider this case of multiple different layers, and to be honest I'm not using the plugin myself at the moment (after I figured out browser support wasn't quite where I wanted a few years ago). I think this should be pretty straightforward to add, though. What do you think of an API like this?

require('postcss-assign-layer')([
  {
    include: '**/styles/**.{css,scss}',
    layerName: 'base',
  }, 
  {
    include: '**/components/**/*.{css,scss}',
    layerName: 'components',
  },
])

It would be a breaking change, but I think that's fine.

@sambedingfield
Copy link
Author

That would be great! 🙏

Yeah, now that layers have been well supported for a couple of years I'm much more comfortable using them.

@IanVS IanVS closed this as completed in #2 Feb 12, 2024
IanVS added a commit that referenced this issue Feb 12, 2024
Fixes #1

This changes the config from a single object into an array of objects.  This allows more flexibility if you have multiple different kinds of files that you want to wrap in layers (though if you only have a few, you should probably just add the layers to the files themselves for extra clarity when editing).
@IanVS
Copy link
Collaborator

IanVS commented Feb 12, 2024

Alright, 0.2.0 is pushed up, let me know how it works for ya!

@sambedingfield
Copy link
Author

Just the job! Thanks for such a quick response and update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants