【发布时间】:2016-04-08 13:07:23
【问题描述】:
在我的 React 项目中,我使用这个 gem 来创建仪表板:https://github.com/luqin/react-icheck
我将他们的第一个示例复制粘贴到我的代码中。
在 Github 页面上,它说我应该像这样导入 css:
import 'icheck/skins/all.css'; // or single skin css
如果我这样做,我会收到错误:
ERROR in ./~/icheck/skins/all.css
Module parse failed: node_modules/icheck/skins/all.css Line 3: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| /* iCheck plugin skins
| ----------------------------------- */
| @import url("minimal/_all.css");
| /*
| @import url("minimal/minimal.css");
如果我这样导入:
import 'icheck';
没有更多错误,但页面没有任何复选框。
那么我怎样才能正确地进行这个导入呢?
我也尝试过使用style-loader,所以我的代码如下所示:
import React from 'react';
import {Checkbox, Radio} from 'react-icheck';
import 'icheck';
require("style!raw!icheck/skins/all.css");
var Criteria = React.createClass({
getInitialState: function() {
return {showGallery: false, showOtherCriteria: false};
},
toggleShowGallery: function() {
this.setState({showGallery: !this.state.showGallery});
},
toggleShowOtherCriteria: function() {
this.setState({showOtherCriteria: !this.state.showOtherCriteria});
},
render: function() {
return (
<div>
<div onClick={this.toggleShowOtherCriteria} className="btn-group" role="group" aria-label="...">
<button type="button" className="btn btn-default">Cold</button>
</div>
{style.use()}
{this.state.showOtherCriteria
?
<div onClick={this.toggleShowGallery} id="channels" className="span12">
<Checkbox
checkboxClass="icheckbox_square-blue"
increaseArea="20%"
label="Checkbox"
/>
<Checkbox
id="checkbox1"
checkboxClass="icheckbox_square-blue"
increaseArea="20%"
/>
<label for="checkbox1">First name</label>
<Radio
name="aa"
radioClass="iradio_square-blue"
increaseArea="20%"
label="Radio"
/>
</div>
:
null
}
{style.unuse()}
</div>
);
}
});
module.exports = Criteria;
但是,现在我明白了:
Module not found: Error: Cannot resolve module 'raw'
如何正确使用style-loader?
【问题讨论】:
-
如果你使用 webpack,你需要
style-loader和css-loader -
我更新了我的代码以使用
style-loader。 -
你需要
webpack.config.js来配置和使用 webpack 加载器。 -
我需要在
webpack.config.js中添加什么代码?
标签: javascript html css reactjs