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

Composing from another file results in undefined #1

Closed
NogsMPLS opened this issue Jan 12, 2016 · 8 comments
Closed

Composing from another file results in undefined #1

NogsMPLS opened this issue Jan 12, 2016 · 8 comments

Comments

@NogsMPLS
Copy link

given some css like this:

.base {
  composes: inline-block from '../styles.css';
  color: red;
}

.babelrc like this:

"plugins": [
        ["css-modules-transform", { "generateScopedName": "test_[name]__[local]" }]
    ]

the plugin outputs this:

var _button = {
    'base': 'test_component__base undefined',
}
@NogsMPLS
Copy link
Author

this is confusing for me, because the repo's test works. with style composing from parent...

I wonder if it has something to do with the babelrc config...i'll keep looking into it, if it ends up being with this repo I'll try and fix and submit a PR.

@NogsMPLS
Copy link
Author

Ah, it's because those classes were being imported into the css file via @import, which is outside the scope of this project I believe. I'll close this now.

@NogsMPLS
Copy link
Author

Thought I'd post this here, as I got it working for me and it might be beneficial for future users that want to have a little more customization re: postcss plugins.

It's pretty simple really. just fork the repo and add the plugins you need to the src/index.js file, and add the prepend option to the css-modules-require-hook.

+ import cssnext from 'postcss-cssnext';
+ import postcssImport from 'postcss-import';
//stuff
- require('css-modules-require-hook')({ ...defaultOptions, ...opts })
+ require('css-modules-require-hook')({ ...defaultOptions, ...opts, prepend: [postcssImport(), cssnext() ]});

then just build, and take the outputted file and use that in your app/project.

@michalkvasnicak
Copy link
Owner

I think, we can handle that with configuration of this plugin too. We just need to check if options contains prepend prop and require all module names added to it.

Something like this:

{
    "plugins": [
        ["css-modules-transform", { "prepend": ["postcss-cssnext", "postcss-import"] }]
    ]
}

There is only one question @NogsMPLS: are cssnext and postcssImport from your example always a functions? If they are, we can call them in this plugin and pass results to prepend.

@NogsMPLS
Copy link
Author

well, i just followed these instructions:

https://github.com/css-modules/css-modules-require-hook#adding-custom-postcss-plugins

However, if we really wanted to extend the usage of this plugin, then you would also want to have pre-processing support as described here: https://github.com/css-modules/css-modules-require-hook#using-stylus-as-a-preprocessor and here https://github.com/css-modules/css-modules-require-hook#preprocesscss-function

That way there could even be SASS/LESS/etc. support if we provide good enough documentation

@michalkvasnicak
Copy link
Owner

It isn't a problem because we can specify js files to load in options. So one will do something like this:

.babelrc

{
    "plugins": [
        ["css-modules-transform", { "preprocessCss": "./preprocess.js" }]
    ]
}

preprocess.js

var stylus = require('stylus');

export default function (css, filename) {
    return stylus(css)
      .set('filename', filename)
      .render();
}

@michalkvasnicak
Copy link
Owner

@NogsMPLS now you can specify functions in cofiguration, see README

@NogsMPLS
Copy link
Author

NogsMPLS commented Feb 3, 2016

This is awesome by the way, thanks for your hard work!

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

No branches or pull requests

2 participants