在ReactJs上使用纯引导v4不起作用
我非常想在React.js应用程序上使用纯引导v4。我使用CreateReact应用程序创建了我的应用程序。因此,我将引导资产放在index.html(公共文件夹)上 在第一次尝试时,它运行良好。然后,我添加了一些依赖项,如在ReactJs上使用纯引导v4不起作用,reactjs,express,webpack,react-router-v4,Reactjs,Express,Webpack,React Router V4,我非常想在React.js应用程序上使用纯引导v4。我使用CreateReact应用程序创建了我的应用程序。因此,我将引导资产放在index.html(公共文件夹)上 在第一次尝试时,它运行良好。然后,我添加了一些依赖项,如react-router-dom,react-router-config,以及prop-types。突然,它几乎显示了一个空白页 1)项目文件夹 2)kodebaru/webpack.config.js const path = require('path'); modu
react-router-dom
,react-router-config
,以及prop-types
。突然,它几乎显示了一个空白页
1)项目文件夹
2)kodebaru/webpack.config.js
const path = require('path');
module.exports = {
entry: path.join(__dirname, '/client/src/index.jsx'),
output: {
path: path.join(__dirname, '/client/dist/js'),
filename: 'app.js',
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, '/client/src'),
loader: 'babel-loader',
query: {
presets: ["react", "es2015"]
}
}
]
},
watch: true
};
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.resolve(__dirname, './backend/static/')));
app.use(express.static(path.resolve(__dirname, './client/dist/')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './backend/static/', 'index.html'));
});
const PORT = process.env.PORT || 3500;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});
3)kodebaru/server.js
const path = require('path');
module.exports = {
entry: path.join(__dirname, '/client/src/index.jsx'),
output: {
path: path.join(__dirname, '/client/dist/js'),
filename: 'app.js',
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, '/client/src'),
loader: 'babel-loader',
query: {
presets: ["react", "es2015"]
}
}
]
},
watch: true
};
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.resolve(__dirname, './backend/static/')));
app.use(express.static(path.resolve(__dirname, './client/dist/')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './backend/static/', 'index.html'));
});
const PORT = process.env.PORT || 3500;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});
4)kodebaru/backend/static/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Kodebaru</title>
<link rel="stylesheet" href="./bootstrap/bootstrap.min.css">
</head>
<body>
<div id="root"></div>
<script src="/js/app.js"></script>
</body>
</html>
柯德巴鲁
5)结果
6)警告信息
我知道react应用程序()有一个框架引导。但是,这次我想知道如何在react应用程序中使用纯引导v4?太晚了。但是,我认为回答我自己的问题是好的,因为没有人。解决方案是使用npm安装引导,在index.jsx上导入引导,在网页包配置文件上添加
jQuery
,Popper.js
,以及css加载器
a)使用npm安装引导程序
npm install bootstrap@4.0.0-beta
b)在index.jsx上导入引导
import 'bootstrap';
require('bootstrap/dist/css/bootstrap.css');
c)在网页上添加jQuery和Popper.js
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
})
d)在网页上添加css加载器
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
全面实施情况如下:
1) index.jsx
import React from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from "redux";
import promise from "redux-promise";
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { renderRoutes } from 'react-router-config';
import routes from './routes.js';
import reducers from './redux/reducers/index.js'
import 'bootstrap';
require('bootstrap/dist/css/bootstrap.css');
const createStoreWithMiddleware = createStore(reducers, {}, compose(applyMiddleware(promise)));
ReactDOM.render(
<Provider store = {createStoreWithMiddleware}>
<Router>
{/* kick it all off with the root route */}
{renderRoutes(routes)}
</Router>
</Provider>,
document.getElementById('root')
);
if(module.hot) {
module.hot.accept('./routes.js', function() {
routes();
})
}
有控制台错误吗?html呈现的是什么?@Panther。。如果没有渲染,那么服务器没有发送任何数据?显示一些小提琴或位置来检查@黑豹。。我添加了一些细节,比如CSS的问题。存在与导航相关的标签,它们不会显示。检查并找出它在UI上不可见的原因