Reactstrap不渲染

时间:2019-07-14 13:55:45

标签: reactjs webpack react-bootstrap reactstrap

所以我正在使用reactstrap,并且我已经安装了依赖项Bootstrap和Reactstrap。我也将CDN粘贴到了html文件中。

我认为问题可能出在webpack配置上,但我不确定。 我正在尝试呈现一个按钮,但是它没有显示出其样式,只是一个基本的html按钮。

这就是我所拥有的:

App.jsx:

import React from 'react'
import { Button } from 'reactstrap';

class App extends React.Component {
    render() {
        return (
            <div>
                <Button></Button>
            </div>
        )
    }
}

export default App;

index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './component/App';

//import 'bootstrap/dist/css/bootstrap.min.css';


ReactDOM.render(<App />, document.getElementById('root'));

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial- 
scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>myDesk</title>
</head>
<body>
    <div id='root'></div>



<!-- Main version -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/6.0.1/reactstrap.min.js"></script>

<!-- All optional dependencies version -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/6.0.1/reactstrap.full.min.js"></script>
</body>
</html>

Webpack.config.js:

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: {
    entry: './assets/src/index.js'
},
output: {
    path: __dirname + './assets/src/index.html',
    filename: 'bundle.js'
},
module: {
    rules: [
    {
        use: 'babel-loader',
        test: /\.(js|jsx)$/,
        exclude: /node_modules/
    },
    {
        use: ['style-loader', 'css-loader'],
        test: /\.css$/
    }
    ]
},
resolve: {
    extensions: ['*', '.js', '.jsx']
},
plugins: [
    new HtmlWebpackPlugin({
    template: 'assets/src/index.html'
    })
  ]
};

package.json:

{
"name": "example",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"keywords": [],
"dependencies": {
  "@sailshq/connect-redis": "^3.2.1",
  "@sailshq/lodash": "^3.10.3",
  "@sailshq/socket.io-redis": "^5.2.0",
  "bootstrap": "^4.3.1",
  "react": "^16.8.6",
  "react-dom": "^16.8.6",
  "reactstrap": "^8.0.1",
  "sails": "^1.2.3",
  "sails-hook-apianalytics": "^2.0.3",
  "sails-hook-organics": "^0.16.0",
  "sails-hook-orm": "^2.1.1",
  "sails-hook-sockets": "^2.0.0",
  "sails-mongo": "^1.0.1"
},
"devDependencies": {
  "eslint": "5.16.0",
  "@babel/cli": "^7.5.0",
  "@babel/core": "^7.5.4",
  "@babel/preset-env": "^7.5.4",
  "@babel/preset-react": "^7.0.0",
  "babel-loader": "^8.0.6",
  "babel-preset-react": "^6.24.1",
  "babel-preset-react-hmre": "^1.1.1",
  "grunt": "1.0.4",
  "html-webpack-plugin": "^3.2.0",
  "htmlhint": "0.11.0",
  "lesshint": "6.3.6",
  "npm-run-all": "^4.1.5",
  "rimraf": "^2.6.3",
  "sails-hook-grunt": "^4.0.0",
  "webpack": "^4.35.3",
  "webpack-cli": "^3.3.5",
  "webpack-dev-server": "^3.7.2"
},
"scripts": {
  "start": "NODE_ENV=production node app.js",
  "start:server": "nodemon app.js",
  "start:client": "webpack-dev-server --mode development --open",
  "test": "npm run lint && npm run custom-tests && echo 'Done.'",
  "lint": "./node_modules/eslint/bin/eslint.js . --max-warnings=0 --report-unused-disable-directives && echo '✔  Your .js files look good.'",
  "custom-tests": "echo \"(No other custom tests yet.)\" && echo"
},
"main": "app.js",
"repository": {
  "type": "git",
  "url": "git://github.com/michalruzicka/example.git"
},
"author": "michalruzicka",
"license": "",
"engines": {
  "node": "^10.15"
}

}

请注意,我已经从index.js注释了导入引导程序,因为它导致以下错误:

./ assets / src / index.js中的错误 找不到模块:错误:无法解析“样式加载器”

0 个答案:

没有答案