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

Prevent scoped class names via CLI #104

Open
MaffooBristol opened this issue Jul 12, 2016 · 5 comments
Open

Prevent scoped class names via CLI #104

MaffooBristol opened this issue Jul 12, 2016 · 5 comments

Comments

@MaffooBristol
Copy link

MaffooBristol commented Jul 12, 2016

Hello,

I'm using css-modulesify like so:

browserify -t [babelify --presets es2015 --presets react --presets stage-0] -p [css-modulesify --global -o client2/public/bundle.css] -o client2/public/bundle.js client2/lib/main.jsx

... along with the require code:

import styles from 'react-virtualized/styles.css';

... however, this creates scoped class names such as ._node_modules_react_virtualized_styles__FlexTable__headerColumn, which breaks the CSS for the module. Please bear in mind that I'm quite new to react and browserify so I may just be being thick.

Is there a way of turning off the scoping from the command line? Or if not, is there something I'm missing that would make my components work normally with the scope?

Thanks
Matt

@stoarca
Copy link

stoarca commented Nov 23, 2016

I'm also having trouble with the same issue. I'd like to disable the mangled class names for a single file that I'm importing.

@joshwnj
Copy link
Member

joshwnj commented Nov 24, 2016

Currently it's possible to use https://github.com/postcss/postcss-nested to allow marking blocks as "global". Eg.

:global {
  .a { ... }
  .b { ... }
}

The output will contain .a and .b, without any scoping.

Ideally we'd be able to do

:global {
  @import "file.css";
}

however it looks like there are some ordering issues around that. Something to look into!

@klarkc
Copy link

klarkc commented Oct 26, 2017

@joshwnj How can I use the global with ES6 modules?

In my code I have:

import 'bootstrap/dist/css/bootstrap.css';

that build to a bundle.css. But the bundle have the prefixes.

with postcss-nested I should use this?

:global {
    @import "bootstrap/dist/css/bootstrap.css"
}

@klarkc
Copy link

klarkc commented Oct 27, 2017

I found this answer: postcss/postcss-import#179 (comment)

But it seems not working with css-modulesify:

Error: Cannot find module '!node_modules/bootstrap-vue/dist/bootstrap-vue.css' from ...

@klarkc
Copy link

klarkc commented Oct 27, 2017

I found a workaround using generateScopedName option:

b.plugin(modulesify, {
    output: path.resolve(
      dirs.buildClient,
      'bundle.css',
    ),
    global: true,
    generateScopedName: function(name, filename) {
      var matches = filename.match(/^\/node_modules/);
      if (matches) return name;
      if (process.env.NODE_ENV === 'production') {
        return modulesify.generateShortName(name, filename);
      } else {
        return modulesify.generateLongName(name, filename);
      }
    }
  });

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

4 participants