style-resources icon indicating copy to clipboard operation
style-resources copied to clipboard

Use with PostCSS?

Open callumflack opened this issue 6 years ago • 18 comments

Doesn't seem to be working for PostCSS files. Does it? Can it?

callumflack avatar Dec 17 '18 23:12 callumflack

It does not work for PostCSS files, correctly.

Can you give an example of possible usage?

TheAlexLichter avatar Dec 18 '18 00:12 TheAlexLichter

Just like sass, I save postcss variables in a file. I'm OK to import where required (I've done it 18 months w/ Nuxt) but it'd be great to use this module instead.

callumflack avatar Dec 18 '18 00:12 callumflack

@callumflack Looks like a doable thing!

TheAlexLichter avatar Dec 18 '18 00:12 TheAlexLichter

@manniL that would be very cool! Thankyou

callumflack avatar Dec 18 '18 00:12 callumflack

@callumflack Do you use a plugin for PostCSS variables?

TheAlexLichter avatar Dec 18 '18 11:12 TheAlexLichter

@manniL yes, I use postcss-preset-env to handle compatibility

callumflack avatar Dec 18 '18 22:12 callumflack

@callumflack But postcss-preset-env doesn't include postcss variables like https://github.com/postcss/postcss-simple-vars right?

Can you give me an example how your files would look like (similar to the fixtures for LESS/SASS/Stylus in the repo)?

TheAlexLichter avatar Dec 19 '18 08:12 TheAlexLichter

@manniL sure, here's an example.

postcss-preset-env uses postcss-custom-properties which sticks to the CSS spec. Other plugins are a little more flexible, eg. postcss-css-variables

I'm not sure how simple-vars works as I've not used it but you wouldn't, for example, be able to alter the selector's key via a "variable" if using postcss-custom-properties.

Is that what you mean? It gets quite nuanced.

Ps. I use a postcss.config.js as I can never seem to get it working via nuxt.config.js.

callumflack avatar Dec 19 '18 08:12 callumflack

@manniL btw, I actually npm import a package of css utilities across all my projects, check it here: https://github.com/callumflack/iremono

And this is a good example of a project it's used within: https://github.com/callumflack/callum-flack-design

callumflack avatar Dec 19 '18 08:12 callumflack

I think you should not care about what plugins are used. postcss-preset-env just pick the stream from postcss and process it. I think you should care instead about adding all the .pcss declared files to the stream BEFORE any other plugins.

For example, i use postcss-easy-import before postcss-preset-envto handle imports before process all the files. This one get all the stream (imported files included) and pass it to their internal plugins (following a specific order). I think the behaviour should be something similar, where this module should follow and resolve all the "imports" and pass the stream to the next postcss plugins (if there are) without processing it.

equinusocio avatar Dec 26 '18 23:12 equinusocio

@callumflack Thank you so much! It’s been two hours I try to figure out how to @import a SCSS mixins package from node_modules, without success. Now it works. :)

meduzen avatar Jan 15 '19 17:01 meduzen

Are there any updates on this? I am using PostCSS with precss plugin, which includes PostCSS Advanced Variables to allow for Sass-like variables, conditionals and iterators.

I'm currently using @import statements in each component, but would like to be able to include my variables file and a few mixins in all components by default.

mrwwalmsley avatar Mar 25 '19 19:03 mrwwalmsley

Had no time to work on it yet, nope 😦

TheAlexLichter avatar Mar 26 '19 08:03 TheAlexLichter

I still have all my custom media queries and custom properties in my postcss.config like in the answer here: https://cmty.app/nuxt/nuxt.js/issues/c7516

Do you think that this could be done, so that the variables could be in a .css file instead?

Dan9boi avatar Mar 29 '19 23:03 Dan9boi

Has there been any progress on this?

2xAA avatar Apr 21 '20 14:04 2xAA

When using postcss variables and mixins in Assets folder (as .css files) I can import those in each

It would be awesome to be able to simply define postcss in nuxt.config.js in same way as scss. I guess this is the aim of this plug-in and postcss seems to be widely used.

Is there maybe any other way in nuxt to "auto-include" global variable and mixins for postcss so we do not have to import those in each .vue file?

CMQNordic avatar Jun 15 '20 16:06 CMQNordic

@CMQNordic in your nuxt.config under the CSS property, you can include global styling. I then use the postCSS plugins to load the variables and media-queries (same file), that will be global for the app. I'm not using the style-resources-module though 🤷‍♂️

Here's my setup:

  css: [
    { src: '~assets/css/_normalize.css' },
    { src: '~assets/css/_fonts.css' },
    { src: '~assets/css/_grid.css' },
    { src: '~assets/css/_base.css' },
  ],
...
build: {
    extractCSS: { ignoreOrder: true },
    optimizeCSS: true,
    postcss: {
      plugins: {
        'postcss-mixins': {},
        'postcss-import': {},
        'postcss-nested': {},
        'postcss-partial-import': {},
        'postcss-custom-properties': {
          importFrom: './assets/css/_variables.css',
          preserve: false,
        },
        'postcss-reporter': {},
        'postcss-custom-media': {
          importFrom: './assets/css/_variables.css',
          preset: {
            browsers: 'last 2 versions, ie >= 11',
            stage: 0,
          },
        },
      },
    },

Dan9boi avatar Jun 16 '20 08:06 Dan9boi

Wondering if this will work with the variables / mixins from postcss-advanced-variables?

https://github.com/csstools/postcss-advanced-variables

tbredin avatar Jul 12 '21 02:07 tbredin