michalkvasnicak / babel-plugin-css-modules-transform

Extract css class names from required css module files, so we can render it on server.
MIT License
326 stars 54 forks source link

keepImport #65

Closed morulus closed 6 years ago

morulus commented 6 years ago

I worked with a situation when I need to precompile css-modules, but keeping the ability to use css-loader later. With option keepImport we got the same result, but all import statements (or require expr.) stay kept.

// before
const styles = require('./test.css');
// after
require('./test.css');

const styles = {
    'someClass': 'Test__someClass___2Frqu'
}

But there are some difficulties with the tests - they do not work by default. Is this normal?

michalkvasnicak commented 6 years ago

@morulus could you rebase your PR on new master please?

michalkvasnicak commented 6 years ago

@morulus only one test case is failing. There is a problem with extensions option, somehow it doesn't pick up configured extensions, so it fails on .scss. Do the tests pass locally on your computer?

morulus commented 6 years ago

@michalkvasnicak No. A local test fails too. I did rebase. Local test still fails. And not only extensions. I got multiple fails. should accept file extensions as an array just one of them. There is two kind of failure:

First look like lost files

ENOENT: no such file or directory, open '/Users/morulus/Work/morulus/projects/babel-plugin-css-modules-transform/test/output/parent.css'

The second is strange

AssertionError: expected '/*  imported from css/child.css  */\n\n.child__line___3fweh {\n    display: inline;\n}\n\n/*  imported from parent.css  */\n\n.parent__block___33Sxl {\n    display: block;\n}\n\n/*  imported from styles.css  */\n\n.styles__className___385m0 {\n    color: red;\n}' to equal '.child__line___3fweh {\n    display: inline;\n}\n.parent__block___33Sxl {\n    display: block;\n}\n.styles__className___385m0 {\n    color: red;\n}'
      + expected - actual

      -/*  imported from css/child.css  */
      -
       .child__line___3fweh {
           display: inline;
       }
      -
      -/*  imported from parent.css  */
      -
       .parent__block___33Sxl {
           display: block;
       }
      -
      -/*  imported from styles.css  */
      -
       .styles__className___385m0 {
           color: red;
       }

As if it compares the text with special characters.

A total of 10 errors.

michalkvasnicak commented 6 years ago

@morulus I'm sorry, I'll take a look on this on Weekend.

morulus commented 6 years ago

@michalkvasnicak Thanks. I was busy a lot all week and will be busy the next, so you can take your time.

michalkvasnicak commented 6 years ago

@morulus released as 1.3.0, thank you very much 👍

morulus commented 6 years ago

@michalkvasnicak Good news! Thanks.