react-select
尝试捆绑我css
的jsx
.
react-select
如果我将它的文件dist/react-select.css
包含在我的index.html
:
<link rel="stylesheet" href="./react-select.css">
但是,我不希望必须分发该额外文件的开销。
这是我当前尝试将其捆绑css
在我的内部的基本概述jsx
(我也尝试了其他一些方法)。在theme.jsx
:
import rTSelect from '../stylesheets/react-select.css'
export {rTSelect}
在form.jsx
:
import classNames from 'classnames/bind'
import Select from 'react-select'
import {rTSelect} from './theme'
class MySelect extends React.Component {
constructor(props) {
super(props)
this.className = {}
}
_handleChange (value) {
this.props.parentFunc(value)
}
render () {
let cx = classNames.bind(rTSelect)
this.className = cx({Select: true})
return (
<Tooltip title={this.props.tip} position="top">
<Select
className={this.className}
placeholder={this.props.placeHolder}
searchable={this.props.searchable}
disabled={this.props.disabled}
clearable={this.props.clearable}
options={this.props.selections}
value={this.props.selection}
onChange={this._handleChange.bind(this)}
/>
</Tooltip>
)
}
}
这种方法似乎适用于其他组件(尽管我不必使用classnames/bind
)。
我承认我不会react
经常使用 - 我学到的东西足以让它发挥作用,所以我不是那么精通,对正在发生的事情只有一个模糊的概念css
。无论如何,我检查了我package.json
的,一路上,我似乎发现需要安装以下css
相关dependencies
:
react-css-modules
react-css-themr
normalize.css
postcss
postcss-cssnext
postcss-modules-values
并且devdependencies
:
css-loader
postcss-import
postcss-loader
style-loader
非常感谢任何帮助!