Я пытаюсь использовать ReactTable, используя эту ссылку
Проблема:
В моем компоненте при попытке импортировать
import 'react-table/react-table.css'
css не получает импорт
Когда я проверяю, я вижу это как URL css
blob:http://localhost:8080/cfd98537-05a8-4091-9345-d6ae877d3d25
, но это работает
<link rel="stylesheet" href="node_modules/react-table/react-table.css">
Файлы:
webpack.config.js
const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require("path");
const htmlWebpackPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
});
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve("dist"),
filename: "main.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
modules: true,
importLoaders: 1,
localIdentName: "[name]_[local]_[hash:base64]",
sourceMap: true,
minimize: true
}
}
]
}
]
},
plugins: [htmlWebpackPlugin]
};
index.js
import React from "react";
import ReactDOM from "react-dom";
import EmpTable from "./components/Emptable.js";
import "react-table/react-table.css";
function renderApp() {
ReactDOM.render(<EmpTable />, document.getElementById("root"));
}
renderApp();
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>React and Webpack4</title>
<link rel="stylesheet" href="node_modules/react-table/react-table.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
Emptable.js
import React, { Component } from "react";
import ReactTable from "react-table";
import axios from "axios";
const column = [
{
Header: "User ID",
accessor: "userId"
},
{
Header: "ID",
accessor: "id"
},
{
Header: "Title",
accessor: "title"
},
{
Header: "Completed",
accessor: "completed"
}
];
class EmpTable extends Component {
constructor(props) {
console.log("Loading...");
super(props);
this.state = { value: [], isLoading: false };
this.loadData = this.loadData.bind(this);
}
componentDidMount() {
console.log("componentDidMount");
this.loadData();
}
componentDidCatch(error, info) {
console.log("componentDidCatch");
// You can also log the error to an error reporting service
console.log(error);
}
loadData() {
console.log("loadData");
axios
.get("https://jsonplaceholder.typicode.com/todos")
.then(response => {
this.setState({ value: response.data });
})
.catch(function(error) {
console.log(error);
});
}
render() {
return (
<div>
<button onClick={this.loadData}>Refresh Grid</button>
<ReactTable data={this.state.value} columns={column} />
</div>
);
}
}
export default EmpTable;