我使用 create-react-app 创建了一个应用程序。我通过配置 webpack 文件来使用 CSS 模块。当我使用 reactstrap 时,会出现 Bootstrap 类,但样式不适用。
遵循 https://reactstrap.github.io/ 的说明
也在 index.js 文件中导入了 CSS,但样式不适用。
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]__[hash:base64:5]'
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
},
我试过 import '!style-loader!css-loader!bootstrap/dist/css/bootstrap.css'; https://github.com/reactstrap/reactstrap/issues/778
但它会抛出错误。“意外的符号!”
最佳答案
试试这个:
在 src/index.js 文件中导入 Bootstrap CSS:import 'bootstrap/dist/css/bootstrap.min.css';
。
如果有帮助,请告诉我。
关于出现 css 类但未应用样式 -REACTSTRAP - CSS MODULES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52177914/