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

Add ability to import external css #920

Merged
merged 1 commit into from
Oct 21, 2016

Conversation

frenzzy
Copy link
Member

@frenzzy frenzzy commented Oct 16, 2016

Also closes #375 and #423

- Allows to import external css from node_modules (ref kriasoft#510, kriasoft#824)
- Allows to properly process `url()` statements (ref kriasoft#825)
- Allows to import css without css-modules prefixing (close kriasoft#771)

  ```css
  /* Example: MyTextEditorComponent.css */
  :global {
    @import 'draft-js/dist/Draft.css'; /* external style without prefixing */
  }
  .button { color: red; } /* keep the prefixes for your own style */
  ```

Also closes kriasoft#375 and kriasoft#423
Copy link
Collaborator

@langpavel langpavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevin-chau
Copy link

This feature isn't working for me. I'm trying to the css from a node module called rc-slider ('rc-slider/dist/rc-slider.css') similar to #510 and #771. Using the :global import syntax in my component stylesheet doesn't seem to be working. But I have gotten the external css to load using import s from '!!isomorphic-style-loader!css-loader!rc-slider/dist/rc-slider.css'; or by just linking the css in the html like <link rel="stylesheet" href="https://npmcdn.com/rc-slider@6.1.1/dist/rc-slider.css" />.

I'm not really happy with either one of these work arounds so I'm wondering what I'm doing wrong with my global import.

@frenzzy
Copy link
Member Author

frenzzy commented Feb 22, 2017

It happens because of issue with csstools/postcss-partial-import#35
refs #1123, #1144, #1145
As a temp solution you can rollback this plugin to v2.*
Or consider to start using postcss-global-import plugin:
css-modules/css-modules#65 (comment)

@glenne
Copy link

glenne commented Jun 8, 2017

What is the status of this? kevinchau321 commented on Feb 21 that the :global import did not work. This is also my experience but fortunately his import s from example did work for me.

@frenzzy
Copy link
Member Author

frenzzy commented Jun 8, 2017

@glenne you just need to import external css inside your component:

import React from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import external from 'external.css';
import s from './MyComponent.css';

class MyComponent extends React.Component {
  render() {
    return <div className={s.local}><div className="global">Hi</div></div>
  }
}

export default withStyles(external, s)(MyComponent);

refs #1277, #1274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do you include a CSS file from node_modules without it prefixing? Question: bug with style-loader?
5 participants