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

Separate css in production build #30

Closed
avanes opened this issue Jan 28, 2016 · 7 comments
Closed

Separate css in production build #30

avanes opened this issue Jan 28, 2016 · 7 comments
Milestone

Comments

@avanes
Copy link

avanes commented Jan 28, 2016

Hi. Thank you for nice component.
I faced with issue with react server rendering, when runtime can't access navigator.userAgent and rendering fails. I looked into and found that it is style-loader and its isOldIE method (https://github.com/webpack/style-loader/blob/6664a954/addStyles.js#L13).
I used quick and dirty workaround — custom production build config with ExtractTextPlugin to build css into separate file.
Maybe it is good to do so in your component. Or maybe you can explain, why you choose inline css.

@marksyzm
Copy link

👍 Also agreed - webpack's styling methods are really not great for production work. I have found that I can't get around the styling without using !important so I'd suggest building it as avanes said, and allow people to control how they would like the built CSS file in webpack themselves.

i.e. I can access the style sheet separately if I were using less via:

import 'react-scrollbar/src/less/scrollbar.less';
import 'react-scrollbar/src/less/site.less';

And this way I have options. I don't think people expect CSS to be built inline like this. You could also expose a main file that uses the inline style and create another file without it i.e.

import 'react-scrollbar/src/less/scrollbar.less';
import 'react-scrollbar/src/less/site.less';
import ScrollArea from './scrollArea.jsx';
export default ScrollArea;

And the one without:

import ScrollArea from './scrollArea.jsx';
export default ScrollArea;

@marksyzm
Copy link

As my colleague pointed out, obviously people can get around this with CSS specificity but I expect most would rather not.

@souhe
Copy link
Owner

souhe commented Jan 30, 2016

Hi,
The main reason to use builtin inline styles is that I like when I can import some library or component only with one import/require() statement. For me it's annoying to localize where the main styles are in node_modules and to include them separately. So that's the main reason for doing it that way. But maybe only for me bundling css styles together with component is better solution ;)

@marksyzm I like your idea about creating two dist files. One(default) with inline styles and another without it. So do you think that it's a good solution or you prefer only one, default file without inline styles?

@avanes
Copy link
Author

avanes commented Feb 2, 2016

@souhe I think it'll be great to have main file with inline styles, and another one without inline css (plus third extracted css, or we can still use less from src). It's easy to add resolve.alias to webpack's config to import new files from node_modules folder with short syntax.

@marksyzm
Copy link

marksyzm commented Feb 2, 2016

Yeah, same, main file with, optional one without, so I could do:

var ScrollArea = require('react-scrollbar/no-css');

or

import ScrollArea from 'react-scrollbar/no-css';

@souhe
Copy link
Owner

souhe commented Feb 2, 2016

Ok, i'll do that.

@souhe souhe added this to the 0.4.0 milestone Feb 3, 2016
@souhe
Copy link
Owner

souhe commented Mar 7, 2016

require('react-scrollbar/no-css');

is supported since now in version v0.4.0

@souhe souhe closed this as completed Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants