【发布时间】:2018-11-22 10:54:27
【问题描述】:
最近我决定为 react 和 webpack 构建自己的设置 因此,当导入按钮之类的组件时,我遇到了 UI 库(例如 antd 或 Bulma)的一些问题,它的样式不起作用
这是我的 index.js
import React from 'react';
import ReactDom from 'react-dom';
import 'antd/dist/antd.css';
import { Button } from 'antd';
import './index.css';
const Index = () => (
<div>
<Button type="primary">Primary</Button>
</div>
)
;
ReactDom.render(<Index/>,document.getElementById('root'));
这是我的输出
(我在 imgur 上上传了图片,因为在获得 10 个声望之前,我不能在 StackOverflow 上上传图片)
这是我的 webpack 设置代码
const path= require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports={
entry:path.resolve(__dirname,'src/index.js'),
output: {
path: path.resolve(__dirname,'dist'),
filename: "bundle.js"
},
module: {
rules: [
{
test:/\.js$/,
use:"babel-loader",
exclude:/node_modules/,
},
{
test:/\.(css|scss)$/,
use:[
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
camelCase: true,
localIdentName: '[local]___[hash:base64:5]',
},
},
'sass-loader',
]
},
{
test:/\.less/,
use:[
"less-loader",
]
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
disable: true
}
}
]
},
{
test:/\.(jpg|png|gif)$/i,
exclude:/node_modules/,
use:{
loader: "url-loader",
options:{
limit:8000
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname,'src/index.html')
})
]
};
【问题讨论】: