question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reccomended way to require CSS in webpack?

See original GitHub issue

What is the recommended way to bring in the CSS from this packaged in webpack?

Just doing require('react-select') appears to only bring in the javascript. I was able to get it working by adding require('react-select/less/default.less') or require('react-select/dist/default.css') to my javascript file.

I’m new to node packages so I’m not clear if that is by design or not.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:46
  • Comments:35 (1 by maintainers)

github_iconTop GitHub Comments

91reactions
GabeMedrashcommented, Jul 13, 2015

This should really be included in the documentation.

30reactions
bbthorntzcommented, Oct 28, 2016

Not sure if it helps someone, but I used a small wrapper component for react-select which imports the dependencies. The .jsx file wraps the default <Select /> component in a wrapper class which can be created by css modules.

// Select.jsx (ES6)
import React from 'react';
import ReactSelect from 'react-select';
import styles from './Select.scss';

const Select = (props) => {
    return (
        <div className={styles.wrap}><ReactSelect {...props} /></div>
    )
};

Select.propTypes = {};
Select.defaultProps = {};

export default Select;

The .scss file first runs through the sass-loader and then css-loader (with modules). This allows sass variable configuration and helps namespace the default styles to avoid impacting anything else.

// Select.scss (SASS + CSS Modules)
.wrap {
    :global {
        @import "node_modules/react-select/scss/default.scss";
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

css-loader | webpack - JS.ORG
The css-loader interprets @import and url() like import/require() and will ... store CSS in a JS module) you might want to check out...
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
In this article, we will practice using CSS Modules with a webpack demo project in order to learn how to configure an app...
Read more >
How to import CSS files into webpack? - Stack Overflow
To import webpack/static/css/myfile.css in webpack/entry.js you have to use a relative path. import './static/css/myfile.css';.
Read more >
How to CSS with Webpack 5 - Setup Tutorial
Learn how to use CSS in a Webpack powered JavaScript application . ... First of all, you need to install a CSS loader...
Read more >
Bundling CSS with webpack Loaders
A loader preprocesses a file before it's actually loaded by webpack. We need these loaders because webpack only understands JavaScript, not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found