我正在使用react.js和react-router以及webpack开发webapp.
我想使用react-bootstrap进行样式设置,但我的导航栏似乎没有像这里显示的样式
http://react-bootstrap.github.io/components.html#navbars
这是我的react-bootstrap代码
<Navbar inverse fixedTop>
<Navbar.Collapse>
<Nav bsStyle="pills">
<NavItem href="#"><Link to="/">{this.state.navMenu[0] }</Link></NavItem>
<NavItem href="#"><Link to="/utilities">{this.state.navMenu[3] }</Link></NavItem>
<NavItem href="#"><Link to="/main">{this.state.navMenu[4] }</Link></NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
这些是依赖关系
"devDependencies": {
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"history": "^1.17.0",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"style-loader": "^0.13.0",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1"},
"dependencies": {
"bootstrap": "^3.3.6",
"imports-loader": "^0.6.5",
"react": "^0.14.6",
"react-bootstrap": "^0.28.2",
"react-router": "^2.0.0-rc5"
}
这是webpack.config文件
var webpack = require('webpack');
module.exports = {
entry: [
'babel-polyfill',
'webpack/hot/only-dev-server',
"./app.js",
],
output: {
path: __dirname + '/build',
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.jsx?$/, loaders: ['react-hot', 'babel'], exclude: /node_modules/},
{ test: [/\.jsx?$/, /\.es6$/], exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.css$/, loader: 'style!css' },
]
},
resolve: {
// you can now require('file') instead of require('file.coffee')
extensions: ['', '.js', '.json', '.coffee']
},
plugins: [
new webpack.NoErrorsPlugin(),
]
};
香港专业教育学院试图要求’bootstrap’,但我收到以下错误:未捕获的ReferenceError:jQuery未定义
任何帮助非常感谢请.
最佳答案 你不应该包含bootstrap,因为它将在你的项目中包含所有bootstrap js文件(它们具有依赖性jquery – 因此你会收到错误).您不需要bootstrap js文件,因为您使用的是react-bootstrap.
要包含bootstrap写入的所有css文件:
import style from 'bootstrap/dist/css/bootstrap.css';
之后,您还会遇到其他装载机的问题.这是因为,引导程序样式也使用其他文件.
安装:
npm install --save-dev url-loader
你必须添加到webpack配置加载器:
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
},
在样式加载器文档页面中,作者建议使用带有css-loader的样式加载器.改变这个:
{ test: /\.css$/, loader: 'style!css' },